一个简单的问题,送50分!(50分)

  • 主题发起人 主题发起人 菜鸟黄
  • 开始时间 开始时间

菜鸟黄

Unregistered / Unconfirmed
GUEST, unregistred user!
问下,怎样响应键盘复合键的事件?
如:我想响应Ctrl+Enter的事件,应该怎样写?
 
请大家帮个忙啊~
 
procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(edit1.Handle, WM_KEYDOWN, VK_CONTROL, MapVirtualKey(VK_CONTROL,0) shl 16 or 1);
PostMessage(edit1.Handle, WM_KEYDOWN, ord('Z'), MapVirtualKey(ord('Z'),0) shl 16 or 1);

PostMessage(edit1.Handle, WM_KEYUP, VK_CONTROL, MapVirtualKey(VK_CONTROL,0) shl 16 or 1);
PostMessage(edit1.Handle, WM_KEYUP, ord('Z'), MapVirtualKey(ord('Z'),0) shl 16 or 1);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.SetFocus;
keybd_event( VK_Control, MapVirtualKey(VK_Control, 0 ), 0 , 0 ); //Control key down
keybd_event( ord('Z'), MapVirtualKey(ord('Z'), 0 ), 0 , 0 ); //Control key down
//keybd_event( VK_MENU, MapVirtualKey(VK_MENU, 0 ),KEYEVENTF_EXTENDEDKEY, 0 ); // Alt down
//keybd_event( VK_Down, MapVirtualKey(VK_Down, 0 ),KEYEVENTF_EXTENDEDKEY, 0 ); // down arrow key down
keybd_event( VK_Control, MapVirtualKey(VK_Control, 0 ), KEYEVENTF_KEYUP , 0 ); //Control arrow key up
keybd_event( ord('Z'), MapVirtualKey(ord('Z'), 0 ), KEYEVENTF_KEYUP , 0 );
//keybd_event( VK_MENU, MapVirtualKey(VK_MENU, 0 ), KEYEVENTF_KEYUP , 0 ); //Alt key up
//keybd_event( VK_Down, MapVirtualKey(VK_Down, 0 ), KEYEVENTF_KEYUP , 0 ); //Down key up

end;
 
to sbzldlb 这样行吗?
 
我试过不行呢~我想就做成QQ发信息的样子
 
procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin // Edit1 -> OnKeyUp事件就可以
if ssCtrl in Shift then
if key=13 then
showmessage('Ctrl+Enter');
end;
 
OK了,谢谢bbscom的帮助,50分就给你了
 
接受答案了.
 
procedure TForm1.suiEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Shift=[ssctrl] then
begin
if key = 13 then
begin
//你要做的事
end;
end;
end;
 
后退
顶部