张无忌请进!!!(50分)

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

jbas

Unregistered / Unconfirmed
GUEST, unregistred user!
谢谢了!分不多了,见谅了:)<br>老大能不能也帮我以下呀?谢谢了!<br>function hookproc(icode:integer;wpadram:wparam;lparam:lparam):lresult;stdcall;<br>var<br>evtmsg:teventmsg;<br>begin<br>evtmsg:=peventmsg(lparam)^;<br>if evtmsg.message=WM_keyDOWN then<br>&nbsp; begin<br>&nbsp; &nbsp; if form1.IsKey(evtmsg.paramL)=true then &nbsp; &nbsp; &nbsp; &nbsp;//如果为true,则不打这个字,否则不做处理.<br>&nbsp; &nbsp; &nbsp;// &nbsp; form1.Label1.Caption:='不能碰那个键'<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; result:=1;//不行呀!!!<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp;// else<br>&nbsp; &nbsp;// &nbsp; &nbsp;form1.Label1.Caption:='可以碰那个键';<br>&nbsp; &nbsp;end;<br><br>end;<br>
 
const<br>&nbsp; &nbsp;_KeyPressMask = $80000000; <br>if ((lParam and _KeyPressMask) = 0)and &nbsp;//屏蔽'B'键用如下代码<br>&nbsp; &nbsp; &nbsp;(wParam=Ord('B')) then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;Result:=1;<br>&nbsp; &nbsp; &nbsp; &nbsp;MessageBeep(0);<br>&nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp;end;
 
先谢了,我试试!
 
老大不行呀,帮我看看。<br>unit Unit1;<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; Button1: TButton;<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; Label2: TLabel;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; &nbsp; &nbsp;function IsKey(lp: integer):boolean;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; hook:integer;<br>implementation<br><br>{$R *.dfm}<br>function tform1.IsKey(lp: integer):boolean;<br>begin<br>&nbsp; result:=false;<br>&nbsp; case lp of<br>&nbsp; &nbsp; 7745: result := true; {A}<br>&nbsp; &nbsp; 12354: result := true;{B}<br>&nbsp; &nbsp; 11843: result :=true; {c}<br>&nbsp; &nbsp; 8260: result := true; {d}<br>&nbsp; &nbsp; 4677: result := true; {e}<br>&nbsp; &nbsp; 8518: result := true; {f}<br>&nbsp; &nbsp; 8775: result := true; {g}<br>&nbsp; &nbsp; 9032: result := true; {h}<br>&nbsp; &nbsp; 5961: result := true; {i}<br>&nbsp; &nbsp; 9290: result := true; {j}<br>&nbsp; &nbsp; 9547: result := true; {k}<br>&nbsp; &nbsp; 9804: result := true; {l}<br>&nbsp; &nbsp; 12877: result := true;{m}<br>&nbsp; &nbsp; 12622: result := true;{n}<br>&nbsp; &nbsp; 6223: result := true; {o}<br>&nbsp; &nbsp; 6480: result := true; {p}<br>&nbsp; &nbsp; 4177: result := true; {q}<br>&nbsp; &nbsp; 4946: result := true; {r}<br>&nbsp; &nbsp; 8019: result := true; {s}<br>&nbsp; &nbsp; 5204: result := true; {t}<br>&nbsp; &nbsp; 5717: result := true; {u}<br>&nbsp; &nbsp; 12118: result := true;{v}<br>&nbsp; &nbsp; 4439: result := true; {w}<br>&nbsp; &nbsp; 11608: result := true;{x}<br>&nbsp; &nbsp; 5465: result := true; {y}<br>&nbsp; &nbsp; 11354: result := true;{z}<br>&nbsp; end;<br>end;<br><br>function hookproc(icode:integer;wparam:wparam;lparam:lparam):lresult;stdcall;<br>const<br>&nbsp; &nbsp;_KeyPressMask = $80000000;<br>//var<br>//evtmsg:teventmsg;<br>begin<br>//evtmsg:=peventmsg(lparam)^;<br>if ((lParam and _KeyPressMask)=0) and (wparam=Ord('B')) then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;Result:=1;<br>&nbsp; &nbsp; &nbsp; // MessageBeep(0);<br>&nbsp; &nbsp; &nbsp; form1.Label1.Caption:='no';<br>&nbsp; &nbsp; &nbsp;end;<br>{if evtmsg.message=WM_keyDOWN then<br>&nbsp; begin<br><br>&nbsp; &nbsp; if form1.IsKey(evtmsg.paramL)=true then<br>&nbsp; &nbsp; &nbsp; &nbsp; form1.Label1.Caption:='不能碰那个键'<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; form1.Label1.Caption:='可以碰那个键';<br>&nbsp; &nbsp;end;<br>}<br>end;<br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>hook:=setwindowshookex(WH_JOURNALRECORD,hookproc,hinstance,0);<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br>unhookwindowshookex(hook);<br>hook:=0;<br>end;<br><br>end.<br>
 
老大,你用的是什么钩子呀,WH_JOURNALPLAYBACK不行呀?
 
我要的效果是拦截a,b,c....z键,不让他们在edit中输入。
 
我用的是键盘钩子啊, 我测试了没有任何问题,达到你的目的用的了钩子么?[:D]<br>在EditKeyPress事件里加<br>if &nbsp;not (key in ['a','b']) then<br>&nbsp; &nbsp; key:=#0;
 
老大,我用的是日志钩子WH_JOURNALPLAYBACK,实现全局监视的,如果<br>在EditKeyPress事件里加<br>if &nbsp;not (key in ['a','b']) then<br>&nbsp; &nbsp; key:=#0;<br>只能监视自己的form,不能全局监视的。帮我了。
 
我用的是WH_KEYBOARD
 
谢谢老兄的一直关注!我有个替换的办法了。 <br>function hookproc(icode:integer;wparam:wparam;lparam:lparam):lresult;stdcall;<br>var<br>&nbsp; evtmsg:teventmsg;<br>begin<br>evtmsg:=peventmsg(lparam)^;<br>if evtmsg.message=WM_keyDOWN then<br>&nbsp; begin<br>&nbsp;// if Chr(LOBYTE(LOWORD(evtmsg.paramL)))='A' then &nbsp;//原来还可以这样,真是好呀!<br>&nbsp; &nbsp; if form1.IsKey(evtmsg.paramL)=true then<br>&nbsp; &nbsp; &nbsp;postmessage(form1.edit1.Handle, WM_keyDOWN , VK_BACK, 0);//删除算了。<br>&nbsp; &nbsp;end;<br><br>end;<br><br>
 
接受答案了.
 

Similar threads

I
回复
0
查看
746
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部