Jump to content

Creating access keys


Recommended Posts

Hi,

I would like to set up access keys to each of the controls on a form, so that the user just has to press Alt and a key to get to a control. I thought that all that was required was to put a & in front of the appropriate letter within the caption of the control, but this does not just allow Alt+key to be used; it also allows Shift+key and Ctrl+key and even just the key itself to be used, as you can see in the following example:

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
$frmTest = GUICreate("Test", 233, 137, 193, 123)
GUISetOnEvent($GUI_EVENT_CLOSE, "frmTestClose")
$cmdButton1 = GUICtrlCreateButton("&Test 1", 12, 28, 73, 29, 0)
$cmdButton2 = GUICtrlCreateButton("T&est 2", 12, 62, 73, 29, 0)
$cmdButton3 = GUICtrlCreateButton("Te&st 3", 12, 96, 73, 29, 0)
$lblTest = GUICtrlCreateLabel("Te&xt", 112, 34, 29, 17)
$inpTest = GUICtrlCreateInput("Some text", 144, 30, 61, 21)
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd
        
Func frmTestClose()
    GUIDelete($frmTest)
    Exit
EndFunc

When I set the form up the same way in Visual Basic, only Alt+key can be used. This is what I would expect and is what I would like to achieve in AutoIt.

Please can you tell me how to set things up so that only Alt+key works, and not all the other combinations, as I would like to use Shift and Ctrl for other purposes.

Thanks for your help.

Regards,

Jonny

Link to comment
Share on other sites

Thank you both for your replies.

I have investigated them both, and found out that HotKeySet was not suitable anyway (in addition to the reason stated by Emiel) because Alt+key has to be pressed and also released before the function is executed. This is not standard Alt+key behaviour, where the function should be executed as soon as Alt and the key are pressed down.

So I'll be going with Emiel's solution.

Regards,

Jonny

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...