Sign in to follow this  
Followers 0
jonny1234

Creating access keys

4 posts in this topic

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

Share this post


Link to post
Share on other sites



Use _IsPressed with WinActive instead , this will only be activated when program is active

HotKeySet is as long as the program is run active

#Include <Misc.au3>
; This is CTRL and P
While 1 
   If BitAND (_IsPressed ("11"), _IsPressed ("50")) and WinActive ("GUIName") Then ExecuteFunction ()
Wend

Best regards,Emiel Wieldraaijer

Share this post


Link to post
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

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