hitting enter clicks OK button

Get help with using AutoHotkey and its commands and hotkeys
sbrady
Posts: 105
Joined: 15 Mar 2014, 20:41
Location: Virginia Beach

hitting enter clicks OK button

12 Jan 2018, 10:34

I have a GUI with text on it and a button. I am making a glorified message box. I have a button on the GUI.
How do I make it so when you hit ENTER, its like clicking the OK button.
User avatar
noname
Posts: 509
Joined: 19 Nov 2013, 09:15

Re: hitting enter clicks OK button

12 Jan 2018, 11:00

Gui, Add, Button, Default, OK

The example above includes the word Default in its Options to make "OK" the default button. The default button's action is automatically triggered whenever the user presses ENTER,
From the help file.
soundcloud.com/user-32706894
garry
Posts: 1903
Joined: 22 Dec 2013, 12:50

Re: hitting enter clicks OK button

12 Jan 2018, 11:07

@noname, thank you
it works first time , but when I use the button TEST is the button TEST default (?)

Code: Select all

Gui,add,button,x10 y10 w50 h25 gA0         ,TEST
Gui,add,button,x10 y40 w50 h25 gA1 +default,OK
Gui,show,x10 y10 h90 w150,TEST-GUI
return

Guiclose:
exitapp

a0:
msgbox,You clicked TEST
return

$enter::
a1:
msgbox,You clicked OK / or used ENTER
return
sbrady
Posts: 105
Joined: 15 Mar 2014, 20:41
Location: Virginia Beach

Re: hitting enter clicks OK button

12 Jan 2018, 11:22

If I hit TAB, the OK button below hightlights, then I hit ENTER and the GUI goes away.

Gui, Add, Button, gTestIt x30 y240 , OK
return

TestIt:
If (GetKeyState("ENTER"))
WinClose GUi window.ahk


How can I get the OK button to default to being hightlighted and close the GUI just by hitting ENTER.
Thanks.
User avatar
noname
Posts: 509
Joined: 19 Nov 2013, 09:15

Re: hitting enter clicks OK button

12 Jan 2018, 11:53

The example above includes the word Default in its Options to make "OK" the default button. The default button's action is automatically triggered whenever the user presses ENTER, except when the keyboard focus is on a different button ...
Sorry sbrady , i do not have a solution for highlighting the focused button , i am surprised it does not seem to be possible. :?
https://autohotkey.com/boards/viewtopic.php?t=38027
and
https://autohotkey.com/boards/viewtopic.php?t=23543

You can use controlfocus to set the correct button focused ( enter will execute it ) but the highlighting stays with the previous one which is confusing for the user.

Greetings
If there is only one button it seems to work even when another control can be focused.

Code: Select all

Gui, Add, Button,  x30 y100 +default, OK 
Gui, add,edit,w200
Gui, show,,test
return

ButtonOk:
winclose
return
soundcloud.com/user-32706894
sbrady
Posts: 105
Joined: 15 Mar 2014, 20:41
Location: Virginia Beach

Re: hitting enter clicks OK button

16 Jan 2018, 12:58

figured it out, so cool, double click the icon, a window pops open to tell you what files it can open,
hit ENTER and the window goes away and any aif or wav files get opened in Audacity.

Code: Select all

Gui, Show, h300 w300

Gui, Font, s18
Gui, Add, Text, h280 w280, This Script opens:`n"aif" and "wav" files`nin Audacity,`r`n`r`nthe files and this script must be located the same place.
Gui, Font, s12
;Gui, Add, Button, default x30 y240 , OK    ;x30  y250  w100 h20   gTestIt
Gui, Add, Button, gTestIt x30 y240 +default, Hit Enter     ;x30 y250 w100 h20
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



TestIt:
If (GetKeyState("ENTER"))
{
;WinClose GUi window.ahk

clips = 

loop, %A_WorkingDir%\*.wav
{
clips = %clips% "%A_LoopFileName%"
}

loop, %A_WorkingDir%\*.aif
{
clips = %clips% "%A_LoopFileName%"
}

loop, %A_WorkingDir%\*.aiff
{
clips = %clips% "%A_LoopFileName%"
}

;loop, %A_WorkingDir%\*.mp3
;{
;clips = %clips% "%A_LoopFileName%"
;}

;clips = "SAL123.wav" "SUE123.aif"

run, "C:\Program Files (x86)\Audacity\audacity.exe\" %clips%
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
}



GuiClose:
GuiEscape:
ExitApp
garry
Posts: 1903
Joined: 22 Dec 2013, 12:50

Re: hitting enter clicks OK button

16 Jan 2018, 17:04

Example for loop

Code: Select all

setworkingdir,%a_scriptdir%
transform,s,chr,34
Gui, Show, h300 w300
Gui, Font, s18
Gui, Add, Text, h280 w280, This Script opens:`n"aif" and "wav" files`nin Audacity,`r`n`r`nthe files and this script must be located the same place.
Gui, Font, s12
Gui, Add, Button,gTestIt x30 y240 +default, Hit Enter
return
Guiclose:
exitapp
;------------------------------------------------
TestIt:
If (GetKeyState("ENTER"))
{
transform,s,chr,34      ;-   ' " '  maybe not needed 
Extensions:= "mp3,wav,aac,aif"      ;- some music extensions
clips :=""
Loop, %a_scriptdir%\*.*, 0, 1
  {
  If A_LoopFileExt in %Extensions%
    clips .= s . A_LoopFileFullPath . s . "`r`n"
  }
msgbox,%clips%      ;- for test
; I didn't find commandline parameters for audacity , have you a link with examples ?
;run, "C:\Program Files (x86)\Audacity\audacity.exe\" %clips%
}
return

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, hasantr, krl, murataygun, nacken012 and 226 guests