AutoHotKey: Hotkey input does not display media keys correctly - autohotkey

I am trying to query a hotkey from a user using the hotkey gui control. It displays most of the entered hotkeys correctly. When I press one of the media keys (play/pause, previous track, next track, volume up/down/mute), though, the input just displays a single character. E.g. when I press "volume up":
When I output the entered key afterwards however, it is correctly displayed:
Minimal example:
Gui, Add, Hotkey, x10 y10 w150 h20 vMyHotkey, %MyHotkey%
Gui, Add, Button, x10 y40 w150 h20 gOK, OK
Gui, Show
return
OK:
Gui, Submit
Msgbox %MyHotkey%
return
Why is the hotkey not displayed correctly in the hotkey input gui control?

Related

Trying to change variable using a checkbox in AHK, but it doesn't seem to be changing the variable at all?

I've been trying to make a pretty basic toggle button to turn hotkeys on and off, but it doesn't seem to be updating the "MyHotkeyCheckboxState" variable at all?
I tried changing it to this script to troubleshoot, but the box is just empty. Any ideas or anything big I'm missing?
; Create a GUI window with a checkbox control
Gui, Add, Checkbox, vMyHotkeyCheckboxState, Enable Hotkey
Gui, Show
; Create a hotkey using PgUp as the keybind
Hotkey, PgUp, MyHotkey, On
return
; Toggle the hotkey based on the state of the checkbox
MyHotkey:
MsgBox, %MyHotkeyCheckboxState%
return
The checkbox status wasn't saved to the variable yet when you checked for it in the MsgBox command.
You just need to add Gui, Submit, NoHide every time you want to check for the checkbox state. NoHide is there so that the target GUI doesn't get hidden.
; Create a GUI window with a checkbox control
Gui, Add, Checkbox, vMyHotkeyCheckboxState, Enable Hotkey
Gui, Show
; Create a hotkey using PgUp as the keybind
Hotkey, PgUp, MyHotkey, On
return
; Toggle the hotkey based on the state of the checkbox
MyHotkey:
Gui, Submit, NoHide
MsgBox, %MyHotkeyCheckboxState%
return
Or using GuiControlGet
; Create a GUI window with a checkbox control
Gui, Add, Checkbox, vMyHotkeyCheckboxState, Enable Hotkey
Gui, Show
; Create a hotkey using PgUp as the keybind
Hotkey, PgUp, MyHotkey
Return
; Toggle the hotkey based on the state of the checkbox
MyHotkey:
GuiControlGet, MyHotkeyCheckboxState
MsgBox, %MyHotkeyCheckboxState%
Return

Use Enter button for submit, while working normally elsewhere

I have a script that opens a GUI with a simple interface, which closes with Esc, and submits through the button. The script always runs in the background. I'm trying to find a way to make the Enter key work as a submit, but while still working normally everywhere else. I've tried using IfWinActive, but it doesn't work. Any ideas? thanks! (btw some of the code looks messy in this format, but the "unnecessary details" are there because this isn't the full script.)
Lwin & MButton::
Goto, Start
return
Start:
IfWinNotExist, New
{
Gui,1:-border
gui, font, s24, Product Sans ; Set 10-point Product Sans.
Gui, Add, Text,, Type here to search: ;controls the UI
Gui, Add, Edit, vTextInput
Gui, Add, Button, -WantReturn gSubmit w80, Go
Gui, Show, w400 h300, New
IfWinExist, New
Hotkey, Enter, Submit, On
return
}
Else
Return
IfWinExist, New
Esc::Gui, Destroy
return
IfWinExist, New
Enter::
Goto, Submit
return
Submit:
Gui, Submit ;destroys the UI when submitted
GuiControlGet, TextInput
Gui, Destroy
Else
{
link = https://www.google.com/search?q= %TextInput% ;search google
Run, %link%
}
The code really looks like some real horror haha.
So much legacy AHK or stuff that doesn't work. But anyway, can't fix all that since that isn't the full script.
The answer to the actual question is to make your button the default button:
Gui, -Border
Gui, Font, s24, % "Product Sans"
Gui, Add, Text, , % "Type here to search:"
Gui, Add, Edit, vTextInput
Gui, Add, Button, +Default gSubmit w80, % "Go"
Gui, Show, w400 h300, % "New"
return
Submit:
Gui, Submit
Run, % "https://www.google.com/search?q=" TextInput
return
Sure, you could also define your own hotkey, like you tried to, but there's just no reason to when the above is so convenient.

Issues with AutoHotKey symbol pasting from GUI

I am new to AHK, and am trying to make a script that opens a GUI with a short list of commonly-used symbols that can be chosen, and then be automatically be pasted.
My code so far:
!+q::
Gui, Add, ListBox, w100 h100, vSymbolChoice, ™|©|°|π|☭|☢|⚠|ツ|•|Ω
Gui, Add, Button, Default, Submit
Gui, Add, Button, default, Cancel
Gui, Show
return
ButtonSubmit:
Gui, Submit
Sleep, 1000
Send, %SymbolChoice%
Gui, Destroy
ButtonCancel:
Gui, Destroy
It creates the GUI and the ListBox but doesn't paste the symbol when I have it selcted and press submit.
Also, is there a better way to detect if a text field is selected than just waiting a second and hoping the user selected the field in that time?
; auto-execute section
; create and show the Gui
Gui, Add, ListBox, w100 h130 vSymbolChoice, ™|©|°|π|☭|☢|⚠|ツ|•|Ω
Gui, Add, Button, Default, Submit
Gui, Add, Button,, Hide ; you can't have two default buttons on a Gui
Gui, Show
return
; Press Alt+Shift+Q to show the hidden Gui after ButtonSubmit or ButtonHide
!+q:: Gui, Show
ButtonSubmit:
GuiControlGet, SymbolChoice ; get the control's contents stored in the variable SymbolChoice (retrieves the ListBox's current selection)
Gui, Submit ; saves the contents of this control to its associated variable SymbolChoice
SendInput, %SymbolChoice%
return
; Hide the Gui
ButtonHide:
Gui, hide
return
; Press ESC or close the Gui to terminate the script
GuiClose:
Esc:: ExitApp
For details see GUI in the documentation.

AutoHotkey ControlFocus fails for Edit Control

I have a window, created by AutoHotkey, with one button and one edit control on it.
What I am trying to do is to bring back the input focus to the Edit control after I click the button. By means of WinSpy (many thanks to Robert Kuster), I have the following information about the Edit control.
Handle : 0x00330786 (changes every time I start the application)
Control ID : 4
Class : Edit
Window Title : some window title
Parent Window Class : AutoHotkeyGUI
Below is the statement I am using in my script.
ControlFocus, MyEdit, some window title
BTW, AutoHotkey help suggests to leave the control name and replace the window title with HWND of the target control as an alternative. Please guide on how to accomplish this.
Below is a piece of Autohotkey script using
GuiControl, Focus, ControlName
in order to change the input focus to the Edit control (namely Completion) after button "Show My Progress" is clicked.
%WinTitle% = some window title
Gui, Add, Text, vLabel cWhite, Reading Completion
Gui, Add, Edit, vCompletion ym w40 ; The ym option starts a new column of controls.
Gui, Add, Progress, vMyProgress w300 h30 xp+50 yp-5
Gui, Add, Button, xp yp+50, Show My Progress
GuiControl,, Completion, %iniCompletion%
Gui, Show, h140, %WinTitle%
ControlClick, Show My Progress, %WinTitle%
**GuiControl, Focus, Completion**
return
ButtonShowMyProgress:
Gui, Submit, NoHide ; Save the input from the user to each control's associated variable.
MyCompletionPercentage:=(Completion / (PageEnd-PageStart+1)) * 100
PercentageRounded:=Round(MyCompletionPercentage,0)
GuiControl,, MyProgress, %PercentageRounded%
**GuiControl, Focus, Completion**
return
Many thanks to MCL and BGM for their comments ...
If I understand correctly, you have your own GUI built with AHK. Why
don't you use GuiControl, Focus? – MCL
MCL has a point. The GuiControl is autohotkey's way of working with it's own controls. You would only use ControlFocus if you are working with controls for
external windows. MCL - maybe you should present that as an answer. – BGM

autohot key using Text Box and a button

Need a little help with a text box and a button..
I have been trying to experiment with "text box" and a "button"..but am not able to do it... I need to take the "values" from the "textbox" field and append it to the button action. i.e., whatever the input is given by the user... need to append it to a "URL"
Example:
If the user is types in "login" as input in the text field, need to take this input and append it to "http://www.google.com/login"
Before action:
http://google.com
AfterAction:
http://google.com/login
Kindly help
Here is my Code:
Gui, Add, Edit, x162 y80 w140 h30 vUserInput, Type here
Gui, Add, Button, x182 y130 w100 h30 gAction, %"Action1" Action1:=http://www.google.om/
; Generated using SmartGUI Creator 4.0
Gui, Show, x127 y87 h379 w479, New GUI Window
Return
Action1:
Gui, Submit, NoHide
guiControlGet, txtVar,, UserInput
guiControl,, UserInput, %( txt++Action1 )
GuiClose:
ExitApp
return
Thanks and cheers.
Okay, you have a few misconceptions and a LOT of errors.
The use of := -vs- % is one of your misunderstandings.
Also, you neglected to put gAction1 as the goto label for your button. You had gAction, but there was no sub called Action.
Another problem is that you have not placed return at the end of your Action1 label.
That means that after the action is completed, the script will continue on to end the script...
You should really read the AutoHotkey Documentation! It will save you a lot of time and headache. Also, you should look at some simple examples.
However, try the script below. Whatever you type into the box, after you push the button, will be appended to the url.
;Now, it may be easier to define your re-usable variable here like this:
;myurl = http://www.google.com/
myurl := "http://www.google.com/" ;this is exactly same as the previous line
Gui, Add, Edit, x162 y80 w300 h30 r1 vUserInput, Type here
Gui, Add, Button, x182 y130 w100 h30 gAction1, Action1 ;The last parameter is JUST the text on the button
;If you wanted to use a variable for the name instead of straight text, you would do this:
;Gui, Add, Button, x182 y130 w100 h30 gAction, %myurl%
;But what you were trying to do is to *assign* a variable instead of *using* a variable - that is, you CAN'T use action1:=value as the variable name
Gui, Show, x127 y87 h379 w479, New GUI Window
Return
Action1: ;the name of this label is the same as the g-action of your button except without the "g" part.
Gui, Submit, NoHide
guiControlGet, UserInput ;you can simply use the edit control's v-name as the output variable
thisurl = %myurl%%UserInput%
guiControl,,UserInput, %thisurl% ;now set the url back to the control
return ;if you don't put return here, the script will continue on and run the GuiClose label...
GuiClose:
ExitApp
return ;you can have this, but you don't need it here since the script will have ended before it gets run anyway.