Sign in to follow this  
Followers 0
Zedna

GUISetAccelerators() as replace for HotKeySet()

4 posts in this topic

#1 ·  Posted (edited)

original example from HelpFile:

#include <GUIConstantsEx.au3>

GUICreate("Custom Msgbox", 210, 80)

GUICtrlCreateLabel("Please click a button!", 10, 10)
$YesID = GUICtrlCreateButton("Yes", 10, 50, 50, 20)
$NoID = GUICtrlCreateButton("No", 80, 50, 50, 20)
$ExitID = GUICtrlCreateButton("Exit", 150, 50, 50, 20)

; Set accelerators for Ctrl+y and Ctrl+n
Dim $AccelKeys[2][2]=[["^y", $YesID], ["^n", $NoID]]
GUISetAccelerators($AccelKeys)

GUISetState()  ; display the GUI

Do
    $msg = GUIGetMsg()

    Select
        Case $msg = $YesID
            MsgBox(0, "You clicked on", "Yes")
        Case $msg = $NoID
            MsgBox(0, "You clicked on", "No")
        Case $msg = $ExitID
            MsgBox(0, "You clicked on", "Exit")
        Case $msg = $GUI_EVENT_CLOSE
            MsgBox(0, "You clicked on", "Close")
    EndSelect
Until $msg = $GUI_EVENT_CLOSE Or $msg = $ExitID

Here is my example:

It assocate my own function Show() with hotkey Ctrl+S --> in my GUI only

If I used HotKeySet() then it would work in all applications here it works only in my GUI which is advantage in some cases

#include <GUIConstantsEx.au3>

GUICreate("Custom Msgbox", 210, 80)

GUICtrlCreateLabel("Please click a button!", 10, 10)
$YesID = GUICtrlCreateButton("Yes", 10, 50, 50, 20)
$NoID = GUICtrlCreateButton("No", 80, 50, 50, 20)
$ExitID = GUICtrlCreateButton("Exit", 150, 50, 50, 20)
$ShowID = GUICtrlCreateDummy()

; Set accelerators for Ctrl+y and Ctrl+n
Dim $AccelKeys[3][2]=[["^y", $YesID], ["^n", $NoID], ["^s", $ShowID]]
GUISetAccelerators($AccelKeys)

GUISetState()  ; display the GUI

Do
    $msg = GUIGetMsg()

    Select
        Case $msg = $YesID
            MsgBox(0, "You clicked on", "Yes")
        Case $msg = $NoID
            MsgBox(0, "You clicked on", "No")
        Case $msg = $ExitID
            MsgBox(0, "You clicked on", "Exit")
        Case $msg = $GUI_EVENT_CLOSE
            MsgBox(0, "You clicked on", "Close")
        Case $msg = $ShowID
            Show()
    EndSelect
Until $msg = $GUI_EVENT_CLOSE Or $msg = $ExitID

Func Show()
  MsgBox(0, "Info", "Hello.")
EndFunc

Note: GUISetAccelerators() is in AutoIt from Beta 3.2.11.3 version

EDIT: fixed corrupted topic after forum upgrade

Edited by Zedna

Share this post


Link to post
Share on other sites



Wow, nobody has commented on this.

I love this implementation, considering HotKeySet() doesn't work on Wine (Yet this does)

Awesome :)

Share this post


Link to post
Share on other sites

Wow, nobody has commented on this.

I love this implementation, considering HotKeySet() doesn't work on Wine (Yet this does)

Awesome :)

Thanks for positive feedback Senton-Bomb :)

Share this post


Link to post
Share on other sites

@Zedna,

Better example.. but i think there should be a note that

Dim $AccelKeys[3][2]=[["^y", $YesID], ["^n", $NoID], ["^s", $ShowID]]

GUISetAccelerators($AccelKeys)

Must be used before GUISetState ()

Best regards,

Emiel


Best regards,Emiel Wieldraaijer

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