delphi 用代码模拟2个鼠标、键盘操作,高手进
1、datetimepicker用鼠标点击右端的箭头才能出现下拉菜单,我希望按回车键就能弹出下拉菜单,应该怎么实现?2、dbgrid用方向键能把光标移动到指定的单元格,用...
1、datetimepicker用鼠标点击右端的箭头才能出现下拉菜单,我希望按回车键就能弹出下拉菜单,应该怎么实现?2、dbgrid用方向键能把光标移动到指定的单元格,用代码又应该怎么定格在指定的单元格呢?例如有一个5*5的dbgrid,点击某个按钮就把光标移到第2行第3列的单元格。本人新手,这2个问题琢磨了很久,请高手们指点一下,先谢了。
展开
展开全部
第一个问题回车实现下拉:
procedure TForm1.DateTimePicker1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then begin
SendMessage(DateTimePicker1.Handle, WM_LBUTTONDOWN, MK_LBUTTON, DateTimePicker1.WIDTH-5);
end;
end;
第二个问题
模拟鼠标的左右键:
Mouse_Event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
Mouse_Event(MOUSEEVENTF_LEFTUP,0,0,0,0);
Mouse_Event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
Mouse_Event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
模拟键盘的方向键:
keybd_event(VK_LEFT,0,0,0);
keybd_event(VK_RIGHT,0,0,0);
keybd_event(VK_UP,0,0,0);
keybd_event(VK_DOWN,0,0,0);
你可以参考一下。
procedure TForm1.DateTimePicker1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then begin
SendMessage(DateTimePicker1.Handle, WM_LBUTTONDOWN, MK_LBUTTON, DateTimePicker1.WIDTH-5);
end;
end;
第二个问题
模拟鼠标的左右键:
Mouse_Event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
Mouse_Event(MOUSEEVENTF_LEFTUP,0,0,0,0);
Mouse_Event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
Mouse_Event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
模拟键盘的方向键:
keybd_event(VK_LEFT,0,0,0);
keybd_event(VK_RIGHT,0,0,0);
keybd_event(VK_UP,0,0,0);
keybd_event(VK_DOWN,0,0,0);
你可以参考一下。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询