Delphi XE2 - 10: Global hotkey -
j have main program works barcode reader , keyboard without keypad. when in program number keys or return key pressed (or simulated via barcode reader) j need check in application (that runs idden in try bar) if insert code stored in database. tried global hotkey. here sample project
type tform1 = class(tform) procedure formcreate(sender: tobject); procedure formdestroy(sender: tobject); private { private declarations } id0, id1, id2, id3 : integer; id4, id5, id6, id7 : integer; id8,id9,identer : integer; code : string; procedure wmhotkey(var msg: twmhotkey); message wm_hotkey; public { public declarations } end; var form1: tform1; implementation {$r *.dfm} procedure tform1.formcreate(sender: tobject); const k_0 = $30; k_1 = $31; k_2 = $32; k_3 = $33; k_4 = $34; k_5 = $35; k_6 = $36; k_7 = $37; k_8 = $38; k_9 = $39; begin // register 0 9 , enter id0 := globaladdatom('k0'); registerhotkey(handle, id0, 0, k_0); id1 := globaladdatom('k1'); registerhotkey(handle, id1, 0, k_1); id2 := globaladdatom('k2'); registerhotkey(handle, id2, 0, k_2); id3 := globaladdatom('key3'); registerhotkey(handle, id3, 0, k_3); id4 := globaladdatom('key4'); registerhotkey(handle, id4, 0, k_4); id5 := globaladdatom('key5'); registerhotkey(handle, id5, 0, k_5); id6 := globaladdatom('key6'); registerhotkey(handle, id6, 0, k_6); id7 := globaladdatom('key7'); registerhotkey(handle, id7, 0, k_7); id8 := globaladdatom('key8'); registerhotkey(handle, id8, 0, k_8); id9 := globaladdatom('key9'); registerhotkey(handle, id9, 0, k_9); identer := globaladdatom('keyenter'); registerhotkey(handle, identer, 0, vk_return); code:=''; end; procedure tform1.formdestroy(sender: tobject); begin unregisterhotkey(handle, id0); globaldeleteatom(id0); unregisterhotkey(handle, id1); globaldeleteatom(id1); unregisterhotkey(handle, id2); globaldeleteatom(id2); unregisterhotkey(handle, id3); globaldeleteatom(id3); unregisterhotkey(handle, id4); globaldeleteatom(id4); unregisterhotkey(handle, id5); globaldeleteatom(id5); unregisterhotkey(handle, id6); globaldeleteatom(id6); unregisterhotkey(handle, id7); globaldeleteatom(id7); unregisterhotkey(handle, id8); globaldeleteatom(id8); unregisterhotkey(handle, id9); globaldeleteatom(id9); unregisterhotkey(handle, identer); globaldeleteatom(identer); end; procedure tform1.wmhotkey(var msg: twmhotkey); begin if msg.hotkey = id0 code:= code +'0'; if msg.hotkey = id1 code:= code +'1'; if msg.hotkey = id2 code:= code +'2'; if msg.hotkey = id3 code:= code +'3'; if msg.hotkey = id4 code:= code +'4'; if msg.hotkey = id5 code:= code +'5'; if msg.hotkey = id6 code:= code +'6'; if msg.hotkey = id7 code:= code +'7'; if msg.hotkey = id8 code:= code +'8'; if msg.hotkey = id9 code:= code +'9'; if msg.hotkey = identer begin showmessage('enter pressed ! ' + #13 + code); code:=''; end; end; end.
this works, if number keys pressed string increase , if return pressed message displyed in other windows application (notepad, i.e. , in main program) keys seem disabled (maybe because hotkeys).
please can have idea(s) on how code typed in main program (not one) in second program (my one)??
thank's appreciate reply
regard
daniele
when called registerhotkey
told system process handle presses of registered key. it's natural key has effect in process , ignored other processes. design.
what need instead use keyboard hook. simplest 1 write low-level keyboard hook. simple because not require injection. use setwindowshookex
passing wh_keyboard_ll
.
Comments
Post a Comment