Jump to content

redefine a hotkey based on realtime user input


DarkBoost
 Share

Recommended Posts

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?

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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