Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make WM_HOTKEY trigger once per full key
#1
In a Dialog I have, I use the WM_HOTKEY
I use the Hotkey to toggle my program on/off.
However if I hold the key in, it goes *fast*on/off/on/off/on/off/on/off/on/off
I looked online and saw the MOD_UPDOWN but did not see it recognized in QM.
I cannot do wait 0 K because I am also running Low level keyboard hooks and it freezes the system for a second.

Is there a simple way to only activate the code 1 time per 1 complete up/down that I am missing?

Function Dialog8
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
#compile CRegisterHotKey
if(!ShowDialog("Dialog8" &Dialog8 0)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Static 0x54000000 0x0 6 8 94 18 "Press and hold Ctrl+K[]Your output will be flooded"
;END DIALOG
;DIALOG EDITOR: "" 0x2030008 "*" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,CRegisterHotKey-- hk
,hk.Register("Ck" hDlg 1); err out _error.description
,
,
,case WM_HOTKEY
,sel wParam
,,case 1 out "If held down this message will spam"
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1



Edit: I figured out a way to do it by:
Creating a global int variable.
In my low level keyboard hook function, increment this variable by 1 on every keydown of the hotkey.
on every keyup i set the variable to 0

In the case WM_HOTKEY: I add, if GLOBE_INT != 1 (skip the code)

If the key is held down, the variable will increment up infinitely but will only run the 1 time, until it is reset when the hotkey comes up.


Forum Jump:


Users browsing this thread: 1 Guest(s)