11-04-2016, 11:42 AM
Function Dialog196
Macro Macro167
Run the first macro, then second. Then press F9, F10, F11. Will be executed A B C button code. To end both threads, close the dialog.
Note: the case code must be as fast as possible, else keys and dialog will hang etc. Or, if need to wait, use opt waitmsg 1. But better run the long-running code in its own thread (mac).
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog196"
;3 Button 0x54032000 0x0 8 8 48 14 "A"
;4 Button 0x54032000 0x0 64 8 48 14 "B"
;5 Button 0x54032000 0x0 120 8 48 14 "C"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040400 "*" "" "" ""
if(!ShowDialog(dd &sub.DlgProc 0)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 3
,out "A"
,
,case 4
,out "B"
,
,case 5
,out "C"
,
,case IDOK
,case IDCANCEL
ret 1
Macro Macro167
int w=win("Dialog196" "#32770")
if(!w) ret
int hh=SetWindowsHookEx(WH_KEYBOARD_LL &sub.Hook_WH_KEYBOARD_LL _hinst 0)
opt waitmsg 1
wait 0 -WC w
UnhookWindowsHookEx hh
#sub Hook_WH_KEYBOARD_LL v
function# nCode message KBDLLHOOKSTRUCT&k
if(nCode<0) goto gNext
if(k.flags&(LLKHF_INJECTED|LLKHF_UP)) goto gNext
;FormatKeyString k.vkCode 0 &_s; out _s ;;debug
sel k.vkCode
,case VK_F9
,SendMessage w WM_COMMAND 3 0 ;;button id 3
,ret 1 ;;"eat" the event so that other application would not receive it; remove this if don't need
,
,case VK_F10
,SendMessage w WM_COMMAND 4 0
,ret 1
,
,case VK_F11
,SendMessage w WM_COMMAND 5 0
,ret 1
,
,;case 'A' ;;example for alpha-numeric keys
;gNext
ret CallNextHookEx(0 nCode message &k)
Run the first macro, then second. Then press F9, F10, F11. Will be executed A B C button code. To end both threads, close the dialog.
Note: the case code must be as fast as possible, else keys and dialog will hang etc. Or, if need to wait, use opt waitmsg 1. But better run the long-running code in its own thread (mac).