Jump to content
Sign in to follow this  
fry128

Anyway to set a customizable hotkey?

Recommended Posts

fry128

Title isnt too clear, so let me elaborate.

I want to create a button that allows a customizable hotkey to call a function. I know about hotkeyset("key", "function") but thats not what I'm interested in.

I want to make the hotkey itself a variable, like inputting a keystroke (variable) and pressing an "ok" button and that would make whatever key I pressed my new hotkey. Kind of like a hotkeyset("(variable)", "function").

I've been trying to get this all day.

Share this post


Link to post
Share on other sites
Steveiwonder

HotKeySet("^.", "_SetHotKey") ; Calls function to set new hotkey
$key = "k"; Default Key to exit script

While 1

    Sleep(100)
WEnd

Func _SetHotkey()

    GUICreate("SetKey", 120, 80, -1, -1)
    $key = GUICtrlCreateInput($key, 10, 5, 40)
    $setKeyBtn = GUICtrlCreateButton("Set Key", 10, 30)
    GUISetState() ; display gui

    While 1
        $msg = GUIGetMsg()

        If $msg = $setKeyBtn Then

            HotKeySet(GUICtrlRead($key), "_exit") ; redefine hotkey
            ConsoleWrite(GUICtrlRead($key) & @CRLF)
            GUIDelete()
            ExitLoop
        EndIf

    WEnd

EndFunc

;function called when you press the user defined hotkey.
Func _exit()

    Exit
EndFunc

That will work, if you want the user to be able to press CTRL+G (example) and then that convert to "^G" then you will need a little more code. Anyway, that should start you off.


They call me MrRegExpMan

Share this post


Link to post
Share on other sites
MilesAhead

Title isnt too clear, so let me elaborate.

I want to create a button that allows a customizable hotkey to call a function. I know about hotkeyset("key", "function") but thats not what I'm interested in.

I want to make the hotkey itself a variable, like inputting a keystroke (variable) and pressing an "ok" button and that would make whatever key I pressed my new hotkey. Kind of like a hotkeyset("(variable)", "function").

I've been trying to get this all day.

I took another approach and made a reusable function to let the user select hotkey modifier and main key from drop down lists. Once I got it perfected I use it in all my AutoIt3 hotkey utilities.

I have a similar dialog for selecting the background color if Glass is enabled on the system.

Check out the screen shot.

Share this post


Link to post
Share on other sites
MilesAhead

Title isnt too clear, so let me elaborate.

I want to create a button that allows a customizable hotkey to call a function. I know about hotkeyset("key", "function") but thats not what I'm interested in.

I want to make the hotkey itself a variable, like inputting a keystroke (variable) and pressing an "ok" button and that would make whatever key I pressed my new hotkey. Kind of like a hotkeyset("(variable)", "function").

I've been trying to get this all day.

I took another approach and made a reusable function to let the user select hotkey modifier and main key from drop down lists. Once I got it perfected I use it in all my AutoIt3 hotkey utilities.

I have a similar dialog for selecting the background color if Glass is enabled on the system.

Check out the screen shot.

For the main key I use the AutoIt3 text as it's self-explanatory "{Home}" "{End}" "{Pause}"

for the modifier keys I use "Alt" "Control" "Shift" "WinKey" "ControlAlt" etc.

I just use a Select case to put "!" in the modifier key variable if the user selects "Alt" or "+!" for "ShiftAlt" etc... The hotkey variable itself I just concatenate the modifier with the main hotkey, with a little bit of error checking. It works out pretty well. Plus I just save the modifier and main parts of the current hotkey to .ini file.

post-31149-12682914875096_thumb.jpg

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.