这是随书光盘的例子,我改了一句,出现了问题,帮我看看!!!(100分)

  • 主题发起人 主题发起人 jh_muse
  • 开始时间 开始时间
J

jh_muse

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Main;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; Label2: TLabel;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Edit2: TEdit;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; ListBox1: TListBox;<br>&nbsp; &nbsp; Edit3: TEdit;<br>&nbsp; &nbsp; Label3: TLabel;<br>&nbsp; &nbsp; Edit4: TEdit;<br>&nbsp; &nbsp; Label4: TLabel;<br>&nbsp; &nbsp; Button3: TButton;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; &nbsp; procedure ListBox1DblClick(Sender: TObject);<br>&nbsp; &nbsp; procedure Edit1Change(Sender: TObject);<br>&nbsp; &nbsp; procedure Edit1KeyPress(Sender: TObject; var Key: Char);<br>&nbsp; &nbsp; procedure Button3Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; function keyhookresult(lp:integer;wp:integer):pchar;<br><br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; hookkey:string;<br>&nbsp; hooktimes:word;<br>&nbsp; hhook:integer;<br><br>&nbsp; PbFlowContrNo:String;<br><br><br>&nbsp; function HookProc(iCode:integer;wParam:wParam;lparam:lParam):LResult;stdcall;<br>implementation<br><br>{$R *.dfm}<br><br>function tform1.keyhookresult(lp:integer;wP:integer):Pchar;<br>begin<br>&nbsp; result:='[Print Screen]';<br>&nbsp; case lp of<br>&nbsp; &nbsp; 14354:result:='[Alt]';<br>&nbsp; &nbsp; 10688:result:='`';<br>&nbsp; &nbsp; 561:result:='1';<br>&nbsp; &nbsp; 818:result:='2';<br>&nbsp; &nbsp; 1075:result:='3';<br>&nbsp; &nbsp; 1332:result:='4';<br>&nbsp; &nbsp; 1589:result:='5';<br>&nbsp; &nbsp; 1846:result:='6';<br>&nbsp; &nbsp; 2103:result:='7';<br>&nbsp; &nbsp; 2360:result:='8';<br>&nbsp; &nbsp; 2617:result:='9';<br>&nbsp; &nbsp; 2864:result:='0';<br>&nbsp; &nbsp; 3261:result:='-';<br>&nbsp; &nbsp; 3515:result:='=';<br>&nbsp; &nbsp; 4177:result:='Q';<br>&nbsp; &nbsp; 4439:result:='W';<br>&nbsp; &nbsp; 4677:result:='E';<br>&nbsp; &nbsp; 4946:result:='R';<br>&nbsp; &nbsp; 5204:result:='T';<br>&nbsp; &nbsp; 5465:result:='Y';<br>&nbsp; &nbsp; 5717:result:='U';<br>&nbsp; &nbsp; 5961:result:='I';<br>&nbsp; &nbsp; 6223:result:='O';<br>&nbsp; &nbsp; 6480:result:='P';<br>&nbsp; &nbsp; 6875:result:='[';<br>&nbsp; &nbsp; 7133:result:=']';<br>&nbsp; &nbsp; 11228:result:='/';<br>&nbsp; &nbsp; 7745:result:='A';<br>&nbsp; &nbsp; 8019:<br>&nbsp; &nbsp; &nbsp; &nbsp;showmessage ('ok'); &nbsp; &nbsp;{这句是我做的修改可是运行时像死机一样不知道为什么<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;如果在这里form.show也不行,好想不能打开其它窗口, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 否则键盘和鼠标就没有响应}<br><br>&nbsp; &nbsp; 8260:result:='D';<br>&nbsp; &nbsp; 8518:result:='F';<br>&nbsp; &nbsp; 8775:result:='G';<br>&nbsp; &nbsp; 9032:result:='H';<br>&nbsp; &nbsp; 9290:result:='J';<br>&nbsp; &nbsp; 9547:result:='K';<br>&nbsp; &nbsp; 9804:result:='L';<br>&nbsp; &nbsp; 10170:result:=';';<br>&nbsp; &nbsp; 10462:result:='''';<br>&nbsp; &nbsp; 11354:result:='Z';<br>&nbsp; &nbsp; 11608:result:='X';<br>&nbsp; &nbsp; 11843:result:='C';<br>&nbsp; &nbsp; 12118:result:='V';<br>&nbsp; &nbsp; 12354:result:='B';<br>&nbsp; &nbsp; 12622:result:='N';<br>&nbsp; &nbsp; 12877:result:='M';<br>&nbsp; &nbsp; 13244:result:=',';<br>&nbsp; &nbsp; 13502:result:='.';<br>&nbsp; &nbsp; 13759:result:='/';<br>&nbsp; &nbsp; 13840:result:='[Right_Shift]';<br>&nbsp; &nbsp; 14624:result:='[Space]';<br>&nbsp; &nbsp; 283:result:='[Esc]';<br>&nbsp; &nbsp; 15216:result:='F1';<br>&nbsp; &nbsp; 15473:result:='F2';<br>&nbsp; &nbsp; 15730:result:='F3';<br>&nbsp; &nbsp; 15987:result:='F4';<br>&nbsp; &nbsp; 16244:result:='F5';<br>&nbsp; &nbsp; 16501:result:='F6';<br>&nbsp; &nbsp; 16758:result:='F7';<br>&nbsp; &nbsp; 17015:result:='F8';<br>&nbsp; &nbsp; 17272:result:='F9';<br>&nbsp; &nbsp; 17529:result:='F10';<br>&nbsp; &nbsp; 22394:result:='F11';<br>&nbsp; &nbsp; 22651:result:='F12';<br>&nbsp; &nbsp; 10768:result:='[Left-Shift]';<br>&nbsp; &nbsp; 14868:result:='CapsLock';<br>&nbsp; &nbsp; 3592:result:='BackSpace';<br>&nbsp; &nbsp; 3849:result:='Tab';<br>&nbsp; &nbsp; 7441:<br>&nbsp; &nbsp; &nbsp; IF wp &gt; 30000 then<br>&nbsp; &nbsp; &nbsp; &nbsp; result:='[Right-Ctrl]'<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; result:='[Left-Ctrl]';<br>&nbsp; &nbsp; 13679:result:='[Num]/';<br>&nbsp; &nbsp; 17808:result:='[NumLock]';<br>&nbsp; &nbsp; 300:result:='[Print Screen]';<br>&nbsp; &nbsp; 18065:result:='[Scroll Lock]';<br>&nbsp; &nbsp; 17683:result:='[Pause]';<br>&nbsp; &nbsp; 21088:result:='[Num]0';<br>&nbsp; &nbsp; 21358:result:='[Num].';<br>&nbsp; &nbsp; 20321:result:='[Num]1';<br>&nbsp; &nbsp; 20578:result:='[Num]2';<br>&nbsp; &nbsp; 20835:result:='[Num]3';<br>&nbsp; &nbsp; 19300:result:='[Num]4';<br>&nbsp; &nbsp; 19557:result:='[Num]5';<br>&nbsp; &nbsp; 19814:result:='[Num]6';<br>&nbsp; &nbsp; 18279:result:='[Num]7';<br>&nbsp; &nbsp; 18536:result:='[Num]8';<br>&nbsp; &nbsp; 18793:result:='[Num]9';<br>&nbsp; &nbsp; 19468:result:='*5*';<br>&nbsp; &nbsp; 14186:result:='[Num]*';<br>&nbsp; &nbsp; 19053:result:='[Num]-';<br>&nbsp; &nbsp; 20075:result:='[Num]+';<br>&nbsp; &nbsp; 21037:result:='[Insert]';<br>&nbsp; &nbsp; 21294:result:='[Delete]';<br>&nbsp; &nbsp; 18212:result:='[Home]';<br>&nbsp; &nbsp; 20259:result:='[End]';<br>&nbsp; &nbsp; 18721:result:='[PageUp]';<br>&nbsp; &nbsp; 20770:result:='[PageDown]';<br>&nbsp; &nbsp; 18470:result:='[Up]';<br>&nbsp; &nbsp; 20520:result:='[Down]';<br>&nbsp; &nbsp; 19237:result:='
';<br>&nbsp; &nbsp; 19751:result:='
';<br>&nbsp; &nbsp; 7181:result:='[Enter]';<br>end;<br>end;<br><br>function HookProc(iCode:integer;wParam:wParam;lparam:lParam):LResult;stdcall;<br>var<br>&nbsp; s:string;<br>begin<br>&nbsp; if (PEventMsg(lparam)^.message = WM_KEYDOWN) then<br>&nbsp; begin<br>&nbsp; &nbsp; s:=format('Down:%5d &nbsp; &nbsp; &nbsp; &nbsp;%5d ',<br>&nbsp; &nbsp; [PEventMsg(lParam)^.paraml,peventMsg(lparam)^.paramh])+<br>&nbsp; &nbsp; form1.keyhookresult(peventmsg(lparam)^.paraml,<br>&nbsp; &nbsp; peventmsg(lparam)^.paramh);<br>&nbsp; &nbsp; form1.listbox1.items.Add(s);<br>&nbsp; &nbsp; if peventmsg(lparam)^.paraml = 8019 then<br>&nbsp; &nbsp; &nbsp; if PbFlowContrNo [2] = '0' then<br>&nbsp; &nbsp; &nbsp; &nbsp; form1.Edit4.text := '0:'+PbFlowContrNo+'-----'+'s';<br>&nbsp; &nbsp; &nbsp; if PbFlowContrNo [2] = '6' then<br>&nbsp; &nbsp; &nbsp; &nbsp; form1.Edit4.Text := '6:'+PbFlowContrNo+'-----'+'s';<br>&nbsp; end<br>&nbsp; else if (peventmsg(lparam)^.message = WM_KEYUP) then<br>&nbsp; begin<br>&nbsp; &nbsp; s:=format(' Up:%5d &nbsp; &nbsp; %5d ',<br>&nbsp; &nbsp; [peventmsg(lparam)^.paraml,peventmsg(lparam)^.paramh])+<br>&nbsp; &nbsp; form1.keyhookresult(peventmsg(lparam)^.paraml,<br>&nbsp; &nbsp; peventMsg(lparam)^.paramh);<br>&nbsp; &nbsp; form1.listbox1.items.add(s);<br>&nbsp; end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; hooktimes:=0;<br>&nbsp; hHook:=0;<br>&nbsp; PbFlowContrNo:= '10000';<br>&nbsp; edit3.text := '10000'<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; inc(hooktimes);<br>&nbsp; if hooktimes = 1 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; hookkey:=Timetostr(now)+' ';<br>&nbsp; &nbsp; &nbsp; hHook:=setwindowshookex(WH_KEYBOARD,hookproc,hinstance,0);<br>&nbsp; &nbsp; &nbsp; MessageBox(0,'键盘监视启动','信息',MB_ICONINFORMATION+MB_OK);<br>&nbsp; &nbsp; END;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; UnHookWindowsHookEx(hHook);<br>&nbsp; hHook:=0;<br>&nbsp; if hooktimes&lt;&gt;0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; messageBox(0,'键盘监视关闭','信息',MB_ICONINFORMATION+MB_OK);<br>&nbsp; &nbsp; end;<br>&nbsp; hooktimes:=0;<br>end;<br><br>procedure TForm1.ListBox1DblClick(Sender: TObject);<br>begin<br>&nbsp; listbox1.Clear;<br>end;<br><br>procedure TForm1.Edit1Change(Sender: TObject);<br>var<br>&nbsp; i:dword;<br>begin<br>&nbsp; if length(edit1.Text)&lt;&gt;1 then exit;<br>&nbsp; i:=mapvirtualkey(ord(edit1.text[1]),0);<br>&nbsp; edit2.text:=format('%d%x',[i,i]);<br>end;<br><br>procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);<br>begin<br>&nbsp; edit1.Text := '';<br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>begin<br>&nbsp; PbFlowContrNo:= edit3.text;<br>end;<br><br>end.​
 
问题一解决!!!!<br><br>哈哈哈哈哈哈!
 
啧啧,听说,你不回复还可以取消了,这下好了,好吧,也祝你解决问题了吧 &nbsp;:)
 

Similar threads

I
回复
0
查看
629
import
I
I
回复
0
查看
787
import
I
后退
顶部