Sign in to follow this  
Followers 0
thewind27

Problem with Hotkey for a GUI Button

2 posts in this topic

#1 ·  Posted (edited)

I want everytime I press button "k" on keyboard, the program will execute the functions for the button I have in my GUI.

This is my code so far:

#include <GUIConstants.au3>
GUICreate("My GUI")
$button1 = GUICtrlCreateButton ("Task 1",  10, 30, 100)
$button2 = GUICtrlCreateButton ( "Task 2",  0, -1)
GUISetState ()
HotKeySet("k", "dotask1")
Func dotask1()
;What should I put here so when I press "k", the program will execute $button1?
EndFunc

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $button1
            ;Execute my task #1.
        Case $button2
            ;Execute my task #2.
    EndSelect
Wend

I have tried

$button1 = GUICtrlCreateButton ("&k Task 1",  10, 30, 100)

but it doesn't work like I expect.

Edited by thewind27

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Maybe GUISetAccelerators() ?

Edit:

Try this, if you click on Button 1 or press K Button1 function will execute.

#include <GUIConstants.au3>
GUICreate("My GUI")
$button1 = GUICtrlCreateButton("Task 1", 10, 30, 100)
$button2 = GUICtrlCreateButton("Task 2", 0, -1)
GUISetState()
HotKeySet("k", "Button1")
Func Button1()
MsgBox(0, '', "Button 1")
EndFunc   ;==>Button1
While 1
$msg = GUIGetMsg()
Select
  Case $msg = $GUI_EVENT_CLOSE
   Exit
  Case $msg = $button1
   Button1()
  Case $msg = $button2
   ;Execute my task #2.
EndSelect
WEnd
Edited by D4RKON3

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