Sign in to follow this  
Followers 0
ratacat

user customizable hotkeys

12 posts in this topic

Does anyone have any / know of any code that shows a good system for letting a user define their own hotkeys. It seems like it should be easy just tunneling userinput to hotkeyset(), but I have not yet found any elegant methods of doing it and was hoping that someone else already had.

much thanks!

Jared

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is very simple, but does the basics of what you want:

#include <GuiConstants.au3>

GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Input_1 = GuiCtrlCreateInput("Input1", 70, 60, 180, 30)
$Button_2 = GuiCtrlCreateButton("Button2", 90, 110, 150, 50)

$old = "^+q"
HotKeySet( $old, "leaveme" )
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
        If $msg = $Button_2 Then
            HotKeySet( $old )
            HotKeySet( GUICtrlRead($Input_1), "leaveme")
        EndIf
    EndSelect
WEnd
Exit


Func leaveme()
    MsgBox(0,"test", "GoodBye")
    Exit
EndFunc

Does that help?

EDIT: Type the hotkey into the edit, and hit the button to set it. The hotkey set should now be the hotkey for exit. I call HotKeySet( $old ) before reassigning so that the old hotkey is removed.

Edited by danwilli

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thankyou Danwilli, that helps me think a bit clearer now. It works very well for using alphanumeric hotkeys. I'm going to try and sort of reverse that. IE. Wait for user keypresses, then record to a hotkey, so that we could utilize Function keys and SHIFT/CTRL etc.

Perhaps _IsPressed may be useful. But as far as I can tell it requires you to define precisely which key you are watching for, that would be overkill because we would need an if statement for every single key and then some(for combinations) to record what the user wants.

Do you know of any functions perhaps that "watch" all keys, and return a value/values based on which may be pressed?

Jared

Edited by xeonz16

Share this post


Link to post
Share on other sites

That would be nice, but if it is "so that we could utilize Function keys and SHIFT/CTRL etc." then you could just add a couple checkboxes to the code I gave you which could add a "^" to the begining if Ctrl is selected, + for Shift, and ! for alt.

Otherwise the method mentioned above would best be done with _IsPressed (In my opinion)

Share this post


Link to post
Share on other sites

good point, perhaps I am trying to make it too concentric. I think using a combination of the checkbox/alphanumeric method, and then perhaps _ispressed for the Function keys might get everything covered. Thanks again for your help.

Jared

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

There are standard Hot Key Controls in Windows but they are not implemetnted in Autoit.

Maybe you can use them indirectly by calling it's API somehow (CreateWindowEx,HKM_SETRULES,HKM_SETHOTKEY,HKM_GETHOTKEY,WM_SETHOTKEY,...)

Edited by Zedna

Share this post


Link to post
Share on other sites

thanks Zedna, I will look into that. I appreciate everyone's input, I'll post when I come up with something nice.

Share this post


Link to post
Share on other sites

Any ideas why I would get a "Cannot redeclare a constant" error message, trying to run this code.

on line 7 ->>> Global Const $WM_USER = 0x0400

it seems to balk on the $WM_USER variable, but it doesn't appear to be declared anywhere else.

Jared

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Any ideas why I would get a "Cannot redeclare a constant" error message, trying to run this code.

on line 7 ->>> Global Const $WM_USER = 0x0400

it seems to balk on the $WM_USER variable, but it doesn't appear to be declared anywhere else.

Jared

What #include statements are there in your script?

That constant is in WindowsConstants.au3, which is included in several other include files.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

yeah, apparently its included in autoit these days. Thanks for the help!

Jared

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