Sign in to follow this  
Followers 0
DarkBoost

redefine a hotkey based on realtime user input

4 posts in this topic

I added HotKeySet() within the "Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)" so that a user can adjust a hotkey realtime however it is not overwriting/updating the Hotkey instead it is adding a new HotKeySet(). Could someone please advise of a better approach to this?

Share this post


Link to post
Share on other sites



DarkBoost,

I posted some code yesterday which does exactly what you want. :)

Take a look and come back if you have any questions or you run into difficulty incorporating the idea into your script. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

ah I see... you set the existing hotkey to "" and then create a new hotkey. I would think that this would still end up creating many hotkeys which are unassigned but maybe still not affecting the scripts performance?

here is my working example:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>

Dim $msg, $input[5]
Dim $hotkey = "x"

GUICreate("hotkey-example", 300, 60)
    $input[0] = 4
    $input[1] = GUICtrlCreateInput($hotkey, 10, 20, 50, 20, $ES_CENTER)
    $input[2] = GUICtrlCreateCheckbox("CTRL", 90, 20, 60, 20, $BS_CENTER)
    $input[3] = GUICtrlCreateCheckbox("ALT", 160, 20, 60, 20, $BS_CENTER)
    $input[4] = GUICtrlCreateCheckbox("SHIFT", 230, 20, 60, 20, $BS_CENTER)
    GUICtrlSetState($input[2], $GUI_FOCUS)
    HotKeySet($hotkey, "hotkey_display")
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Local $hCtrl = $lParam

    HotKeySet($hotkey, "hotkey_empty")
    $hotkey = ""
    If GUICtrlRead($input[2]) = 1 Then $hotkey &= "^"
    If GUICtrlRead($input[3]) = 1 Then $hotkey &= "!"
    If GUICtrlRead($input[4]) = 1 Then $hotkey &= "+"
    If GUICtrlRead($input[1]) <> "" Then $hotkey &= GUICtrlRead($input[1])
    HotKeySet($hotkey, "hotkey_display")
EndFunc

Func hotkey_empty()
EndFunc

Func hotkey_display()
    MsgBox(0, "", $hotkey)
EndFunc
Edited by DarkBoost

Share this post


Link to post
Share on other sites

DarkBoost,

If you think about it, you start with all the possible HotKey combinations unassigned - using HotKeySet just tells Windows that a particular function should be associated with a particular key combination. Unsetting the HotKey just returns that key combination to its original state, so it will certainly not affect performance. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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