Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Barcode Scanner Key logger
#1
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
#2
This macro records keys as text for 5 seconds.

Macro Macro3166
Trigger Ca 0x1     Help - how to add the trigger to the macro
Code:
Copy      Help
;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
#3
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     Help - how to add the trigger to the macro
Code:
Copy      Help
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


Forum Jump:


Users browsing this thread: 1 Guest(s)