1.将Form的KeyPreview:=True; 2.在Form的OnkeyDown事件中: procedure TYourForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var s:String begin s:='您按下了' if ssShift in Shift then s:=s+'Shift键'; if ssCtrl in Shift then s:=s+',Ctrl键'; if ssAlt in Shift then s:=s+',Alt键'; if ssLeft in Shift then s:=s+',鼠标左键'; if ssRight in Shift then s:=s+',鼠标右键'; //........ if s<>'您按下了' then ShowMessage(s); ShowMessage(inttostr(key)); end;
例如:
在某个控件的KEYDOWN事件里:
showmessage(inttostr(key));
就可以看到各个键值的情况啊,在根据键值做你想要做的事
2.在Form的OnkeyDown事件中:
procedure TYourForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
s:String
begin
s:='您按下了' if ssShift in Shift then
s:=s+'Shift键';
if ssCtrl in Shift then
s:=s+',Ctrl键';
if ssAlt in Shift then
s:=s+',Alt键';
if ssLeft in Shift then
s:=s+',鼠标左键';
if ssRight in Shift then
s:=s+',鼠标右键';
//........
if s<>'您按下了' then
ShowMessage(s);
ShowMessage(inttostr(key));
end;
就可以
用hook应该可以,比较复杂.