Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
General hook for keyboard.
#11
Ok here is the whole code, to be debugged and corrected.

Function generic_hook
Code:
Copy      Help
int hh=SetWindowsHookEx(WH_KEYBOARD_LL &generic_hook_Proc _hinst 0)
str+ OldKey
int+ OldTime
out "Press a key"
opt waitmsg 1
wait -1
UnhookWindowsHookEx hh

Function generic_hook_Proc
Code:
Copy      Help
function# nCode message KBDLLHOOKSTRUCT&k
int- TimeOld
if(nCode<0) goto gNext
if(!(k.flags&LLKHF_UP)) goto gNext ;;Si key down, on passe


int time=k.time
int code=k.vkCode
if(TraiteTouches(win time code)) ret 1
;gNext
ret CallNextHookEx(0 nCode message &k)

Function TraiteTouches
Code:
Copy      Help
function int'hwnd int'time int'code
_i=0
int- timeold
_s.getwinexe(hwnd)
str jj
str chacun g
str monitor="qm"
FormatKeyString code 0 &jj
;out "%s %s%s" _s iif(k.flags&LLKHF_UP "up" "down") iif(k.flags&LLKHF_INJECTED ", injected" "") ;;debug
str+ CurrentKey=jj
out "CurrentKey: %s" CurrentKey
out "OldKey: %s" OldKey
OldKey=CurrentKey
int h=time-timeold
out h

timeold=time
foreach chacun monitor
,if(findrx(_s chacun 0 1 g)!=-1)
,,_i+1
,,break
if(_i=0) ret 1

the output is this one, pressing two key one after the other rapidly...seems near to do it, but miss something for being functional...

CurrentKey: P
OldKey: O
250
CurrentKey: M
OldKey: P
2422
CurrentKey: L
OldKey: M
297
CurrentKey: K
OldKey: L
5328
CurrentKey: I
OldKey: K
266
CurrentKey: J
OldKey: I
297
CurrentKey: U
OldKey: J
234
CurrentKey: H
OldKey: U
266
CurrentKey: Y
OldKey: H
250
CurrentKey: J
OldKey: Y
3453
CurrentKey: J
OldKey: J
156
CurrentKey: J
OldKey: J
719
CurrentKey: J
OldKey: J
156


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)