2010年11月15日星期一

如何在当前程序中实现组合快捷键(转)

-------------------------------------ASK----------------------------------------------------------------

I am using TApplicationEvents OnShortCut event to get application keyboard short cuts in a Delphi program.

Using the following code:

procedure TForm1.ApplicationEvents1ShortCut(var Msg: TWMKey; var Handled: Boolean) ;
begin
   
if (Msg.CharCode = VK_F9) then
   
begin
     
ShowMessage('F9 pressed!') ;
     
Handled := True;
   
end;
end;

Question: How do I detect when 'ALT C' has been pressed ?

_____________________ANSWER--------------------------------------------------------------

procedure TForm1.ApplicationEvents1ShortCut(var Msg: TWMKey;
 
var Handled: Boolean);
begin
 
if (Msg.CharCode = Ord('C'))
   
and (HiWord(Msg.KeyData) and KF_ALTDOWN <> 0)
 
then begin
   
ShowMessage('Alt+C pressed!') ;
   
Handled := TRUE;
 
end;
end;

Please note that using Alt and some key only is a bad choice for a shortcut, as the system uses these to activate menu items or dialog controls.

from:http://stackoverflow.com/questions/734990/delphi-using-the-tapplicationevents-onshortcut-event-to-detect-altc-key-presse


没有评论: