求教:如何可以捕获所选菜单,按钮和快捷方式? (300分)

  • 主题发起人 主题发起人 freeboot
  • 开始时间 开始时间
F

freeboot

Unregistered / Unconfirmed
GUEST, unregistred user!
如何可以捕获所选菜单,按钮和快捷方式?如我现在选中“我的电脑”(包括用鼠标和<br>键盘),或者选的是一程序的“菜单”、“文本框”、“按钮”…… &nbsp;则我的程序可以<br>知道选中的内容,并判断出是什么类型(快捷方式、菜单、文本框、按钮……)。<br>最好给出原码,谢谢!!<br><br>分数不够可以再加!!
 
估计只有问微软了。<br>不过好像95下有个什么跟踪软件,可以记录用户的所有操作,你不会想做这个吧
 
用钩子能不能钩住?
 
用钩子记录分析键盘鼠标的每一个动作<br>下面的代码可以重放鼠标和键盘操作过程,希望有所帮助:<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls, Menus;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; Button3: TButton;<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Button4: TButton;<br>&nbsp; &nbsp; PopupMenu1: TPopupMenu;<br>&nbsp; &nbsp; CheckBox1: TCheckBox;<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 Button3Click(Sender: TObject);<br>&nbsp; private<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; EventArr:array[0..10000]of EVENTMSG;<br>&nbsp; EventLog:Integer;<br>&nbsp; PlayLog:Integer;<br>&nbsp; hHook,hPlay:Integer;<br>&nbsp; recOK:Integer;<br>&nbsp; canPlay:Integer;<br>&nbsp; bDelay:Bool;<br><br>implementation<br><br>{$R *.dfm}<br><br>Function PlayProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;<br>begin<br>&nbsp; canPlay:=1;<br>&nbsp; Result:=0;<br>&nbsp; if iCode &lt; 0 then //必须将消息传递到消息链的下一个接受单元<br>&nbsp; &nbsp; Result := CallNextHookEx(hPlay,iCode,wParam,lParam)<br>&nbsp; else if iCode = HC_SYSMODALON then<br>&nbsp; &nbsp; canPlay:=0<br>&nbsp; else if iCode = HC_SYSMODALOFF then<br>&nbsp; &nbsp; canPlay:=1<br>&nbsp; else if ((canPlay =1 )and(iCode=HC_GETNEXT)) then begin<br>&nbsp; if bDelay then begin<br>&nbsp; &nbsp; bDelay:=False;<br>&nbsp; &nbsp; Result:=50;<br>&nbsp; end;<br>&nbsp; pEventMSG(lParam)^:=EventArr[PlayLog];<br>&nbsp; end<br>&nbsp; else if ((canPlay = 1)and(iCode = HC_SKIP))then begin<br>&nbsp; &nbsp; bDelay := True;<br>&nbsp; &nbsp; PlayLog:=PlayLog+1;<br>&nbsp; end;<br>&nbsp; if PlayLog&gt;=EventLog then begin<br>&nbsp; &nbsp; UNHookWindowsHookEx(hPlay);<br>&nbsp; end;<br>end;<br><br>function HookProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;<br>begin<br>&nbsp; recOK:=1;<br>&nbsp; Result:=0;<br>&nbsp; if iCode &lt; 0 then<br>&nbsp; Result := CallNextHookEx(hHook,iCode,wParam,lParam)<br>&nbsp; else if iCode = HC_SYSMODALON then<br>&nbsp; recOK:=0<br>&nbsp; else if iCode = HC_SYSMODALOFF then<br>&nbsp; recOK:=1<br>&nbsp; else if ((recOK&gt;0) and (iCode = HC_ACTION)) then begin<br>&nbsp; &nbsp; EventArr[EventLog]:=pEventMSG(lParam)^;<br>&nbsp; &nbsp; EventLog:=EventLog+1;<br>&nbsp; &nbsp; if EventLog&gt;=10000 then begin<br>&nbsp; &nbsp; &nbsp;UnHookWindowsHookEx(hHook);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; Button1.Caption:='纪录';<br>&nbsp; Button2.Caption:='停止';<br>&nbsp; Button3.Caption:='回放';<br>&nbsp; Button4.Caption:='范例';<br>&nbsp; Button2.Enabled:=False;<br>&nbsp; Button3.Enabled:=False;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; EventLog:=0;<br>&nbsp; //建立键盘鼠标操作消息纪录链<br>&nbsp; hHook:=SetwindowsHookEx(WH_JOURNALRECORD,HookProc,HInstance,0);<br>&nbsp; Button2.Enabled:=True;<br>&nbsp; Button1.Enabled:=False;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; UnHookWindowsHookEx(hHook);<br>&nbsp; hHook:=0;<br>&nbsp; Button1.Enabled:=True;<br>&nbsp; Button2.Enabled:=False;<br>&nbsp; Button3.Enabled:=True;<br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>begin<br>&nbsp; PlayLog:=0;<br>&nbsp; //建立键盘鼠标操作消息纪录回放链<br>&nbsp; hPlay:=SetwindowsHookEx(WH_JOURNALPLAYBACK,PlayProc,<br>&nbsp; HInstance,0);<br>&nbsp; Button3.Enabled:=False;<br>end;<br><br>end.<br><br>object Form1: TForm1<br>&nbsp; Left = 192<br>&nbsp; Top = 107<br>&nbsp; Width = 544<br>&nbsp; Height = 375<br>&nbsp; Caption = 'Form1'<br>&nbsp; Color = clBtnFace<br>&nbsp; Font.Charset = DEFAULT_CHARSET<br>&nbsp; Font.Color = clWindowText<br>&nbsp; Font.Height = -11<br>&nbsp; Font.Name = 'MS Sans Serif'<br>&nbsp; Font.Style = []<br>&nbsp; OldCreateOrder = False<br>&nbsp; OnCreate = FormCreate<br>&nbsp; PixelsPerInch = 96<br>&nbsp; TextHeight = 13<br>&nbsp; object Button1: TButton<br>&nbsp; &nbsp; Left = 16<br>&nbsp; &nbsp; Top = 24<br>&nbsp; &nbsp; Width = 75<br>&nbsp; &nbsp; Height = 25<br>&nbsp; &nbsp; Caption = 'Button1'<br>&nbsp; &nbsp; TabOrder = 0<br>&nbsp; &nbsp; OnClick = Button1Click<br>&nbsp; end<br>&nbsp; object Button2: TButton<br>&nbsp; &nbsp; Left = 16<br>&nbsp; &nbsp; Top = 64<br>&nbsp; &nbsp; Width = 75<br>&nbsp; &nbsp; Height = 25<br>&nbsp; &nbsp; Caption = 'Button2'<br>&nbsp; &nbsp; TabOrder = 1<br>&nbsp; &nbsp; OnClick = Button2Click<br>&nbsp; end<br>&nbsp; object Button3: TButton<br>&nbsp; &nbsp; Left = 16<br>&nbsp; &nbsp; Top = 104<br>&nbsp; &nbsp; Width = 75<br>&nbsp; &nbsp; Height = 25<br>&nbsp; &nbsp; Caption = 'Button3'<br>&nbsp; &nbsp; TabOrder = 2<br>&nbsp; &nbsp; OnClick = Button3Click<br>&nbsp; end<br>&nbsp; object Edit1: TEdit<br>&nbsp; &nbsp; Left = 128<br>&nbsp; &nbsp; Top = 16<br>&nbsp; &nbsp; Width = 361<br>&nbsp; &nbsp; Height = 21<br>&nbsp; &nbsp; TabOrder = 3<br>&nbsp; &nbsp; Text = 'Edit1'<br>&nbsp; end<br>&nbsp; object Button4: TButton<br>&nbsp; &nbsp; Left = 16<br>&nbsp; &nbsp; Top = 136<br>&nbsp; &nbsp; Width = 75<br>&nbsp; &nbsp; Height = 25<br>&nbsp; &nbsp; Caption = 'Button4'<br>&nbsp; &nbsp; TabOrder = 4<br>&nbsp; end<br>&nbsp; object CheckBox1: TCheckBox<br>&nbsp; &nbsp; Left = 224<br>&nbsp; &nbsp; Top = 168<br>&nbsp; &nbsp; Width = 97<br>&nbsp; &nbsp; Height = 17<br>&nbsp; &nbsp; Caption = 'CheckBox1'<br>&nbsp; &nbsp; TabOrder = 5<br>&nbsp; end<br>&nbsp; object PopupMenu1: TPopupMenu<br>&nbsp; &nbsp; Left = 168<br>&nbsp; &nbsp; Top = 104<br>&nbsp; end<br>end<br>
 
用钩子并不能得到所选菜单。<br>反正我试验过没成功。<br>菜单是个很难解决的问题。<br>用楼上的日志钩子挺好,只是不知道顶楼的到底要做什么。
 
在下要做一个盲人用的软件。所有功能要通过键盘实现,而且要实时的才行。
 
不是很明白具体你要实现什么功能,你是要做一个系统监测程序吗?如果要做到实时的功能,<br>恐怕只有钩子一途了。你把具体要求说清楚一点吧!
 
后退
顶部