Sign in to follow this  
Followers 0
Zest

Assign keys to GUI buttons

6 posts in this topic

Hello,

I have a simple GUI with several windows to click through one after another. Each window has 10 buttons that can be clicked. I would like to assign the keys 1 to 0 to these, so that I don't have to use the mouse to click a button but simply press it's number.

I read something about hotkeys but I'm not sure if this is the correct way to set this up or if there is an easier way.

It would be great if there was a way to assign a key to a button directly when creating the button, but I can't find something like this in the docs.

What is the best way to get this functionality?

Any help is appreciated!

Share this post


Link to post
Share on other sites



Press R or B

#include <GUIConstants.au3>

GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered

Opt("GUICoordMode",2)
$Button_1 = GUICtrlCreateButton ("&Run Notepad",  10, 30, 100)
$Button_2 = GUICtrlCreateButton ( "&Button Test",  0, -1)

GUISetState ()      ; will display an  dialog box with 2 button

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            Run('Notepad.exe')    ; Will Run/Open Notepad
        Case $msg = $Button_2
            MsgBox(0, 'Testing', 'Button 2 was pressed')    ; Will demonstrate Button 2 being pressed
    EndSelect
Wend


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Thank you for your answer, but this is not what I meant:

I already have my GUI up and running without problems when I use the mouse, but I want to have it so that when the user presses the "1" key on the keyboard, the script 'presses' the first button. When the user presses the "2" key on the keyboard, the script 'presses' the second button and so on ...

Do you know how to do that ?

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>

GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered

Opt("GUICoordMode",2)
$Button_1 = GUICtrlCreateButton ("&1 Run Notepad",  10, 30, 100)
$Button_2 = GUICtrlCreateButton ( "&2 Button Test",  0, -1)

GUISetState ()      ; will display an  dialog box with 2 button

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            Run('Notepad.exe')    ; Will Run/Open Notepad
        Case $msg = $Button_2
            MsgBox(0, 'Testing', 'Button 2 was pressed')    ; Will demonstrate Button 2 being pressed
    EndSelect
Wend



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Thanks! This is exactly what I needed.

Although the only must is that the numbers are actually in the text (which doesn't bother me) it works great.

I didn't realise the answer was already in your first post: The '&' is used to define the key...

I'm ashamed of my stupidity ... :"> :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0