Jump to content

Problem with Hotkey for a GUI Button


thewind27
 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...