Posts: 1,000
Threads: 253
Joined: Feb 2008
I have a barcode scanner that interfaces with a website to track lunch orders by scanning an ID card with a 6 digit number.
I've programmed the barcode scanner to key CTRL+A as a prefex to remove anything in the input, then it keys the 6 digit number from the scan, and then keys F2 followed by Down and finally enter.
I'd like QM to run in the background to log timestamps and the 6 digit number so I can use them to index video of a camera filming the trays.
It's easy enough to just use a keyboard shortcut "CTRL+A" assigned to a function without the "Eat" checked...but I'm not quite sure about capturing the 6 digit number that is keyed after that.
Thanks in advance!
The Vig
Posts: 12,095
Threads: 142
Joined: Dec 2002
11-19-2021, 04:10 PM
(This post was last modified: 11-19-2021, 04:13 PM by Gintaras.)
This macro records keys as text for 5 seconds.
Macro
Macro3166
Trigger
Ca 0x1
;int w1=act(win("- Notepad" "Notepad"))
str text
int hh=SetWindowsHookEx(WH_KEYBOARD_LL &sub.Hook_WH_KEYBOARD_LL _hinst 0)
opt waitmsg 1
wait 5
UnhookWindowsHookEx hh
out text
#sub Hook_WH_KEYBOARD_LL v
function# nCode message KBDLLHOOKSTRUCT&k
if(nCode<0 or k.flags&LLKHF_UP) goto gNext
;FormatKeyString k.vkCode 0 &_s; out _s ;;debug
word ch=sub.KeyToChar(k.vkCode k.scanCode)
if(ch) text.formata("%C" ch)
;gNext
ret CallNextHookEx(0 nCode message &k)
#sub KeyToChar
function@ vk sc
sel vk
,case VK_PACKET ret sc
,case [VK_LCONTROL,VK_RCONTROL,VK_LSHIFT,VK_RSHIFT,VK_LMENU,VK_RMENU,VK_LWIN,VK_RWIN,VK_BACK,VK_ESCAPE] ret
int mod=GetMod
if(mod&8 or mod~1=2) ret
int w=child
int tid=GetWindowThreadProcessId(w 0); if(!tid) ret
int hkl=GetKeyboardLayout(tid)
ARRAY(byte) ks.create(256)
if(mod&1) ks[VK_SHIFT]=0x80
if(mod&2) ks[VK_CONTROL]=0x80
if(mod&4) ks[VK_MENU]=0x80
ifk(K 1) ks[VK_CAPITAL]=1
long u
int n=ToUnicodeEx(vk sc &ks[0] +&u 4 4 hkl)
if(n!=1) ret
int r=u&0xffff
if(r<32) ret
ret r
Posts: 1,000
Threads: 253
Joined: Feb 2008
11-19-2021, 07:11 PM
(This post was last modified: 11-19-2021, 07:18 PM by TheVig.)
This doesn't seem to work for me. No errors. The QM output remains blank.
QM Version 2.4.11.2 on Windows 10 version 20H2
When commenting out the FormatKeyString k.vkCode 0 &_s; out _s ;;debug line, the text does output in QM.
Got it. Needed to change a couple things.
Macro
Macro6
Trigger
Ca 0x1
str text
int hh=SetWindowsHookEx(WH_KEYBOARD_LL &sub.Hook_WH_KEYBOARD_LL _hinst 0)
opt waitmsg 1
wait 5
UnhookWindowsHookEx hh
out text
#sub Hook_WH_KEYBOARD_LL v
function# nCode message KBDLLHOOKSTRUCT&k
if(nCode<0 or k.flags&LLKHF_UP) goto gNext
FormatKeyString k.vkCode 0 &_s;
;out _s ;;debug
text+_s
word ch=sub.KeyToChar(k.vkCode k.scanCode)
if(ch) text.formata("%C" ch)
;gNext
ret CallNextHookEx(0 nCode message &k)
#sub KeyToChar
function@ vk sc