把全局的键盘事件统统截获,用一个ApplicationEvents控件,响应OnMessage方法,搞定!
procedure TForm_Main.ApplicationEvents_MainMessage(var Msg: tagMSG;
var Handled: Boolean);
begin
if (Msg.message=WM_KEYDOWN) then
begin
//检查键盘状态
GetKeyboardState(KS);
if KeyboardStateToShiftState(KS) <> [] then
Exit;
//处理全局键盘事件
case Msg.wParam of
8: //Backspace
begin
if (self.Edit_Board.Focused() = false) then
self.Init();
Exit;
end;
116: //F5
begin
self.Init();
Exit;
end;
end;
end;