KeyPreview:=True;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=27 then
begin
while (GetKeyState(27)<>0) And (GetKeyState(27)<>1) do
begin
Application.ProcessMessages;
end;
showmessage('Esc_Key Up');
end;
end;如果不加Application.ProcessMessages;
程序进入死循环,加了一直按下ESC键长点时间,执行多次showmessage
按键后再判断键弹起,再执行后面的模块.不要在FormKeyUp中实现
Shift: TShiftState);
begin
if Key=27 then
begin
while (GetKeyState(27)<>0) And (GetKeyState(27)<>1) do
begin
Application.ProcessMessages;
end;
showmessage('Esc_Key Up');
end;
end;如果不加Application.ProcessMessages;
程序进入死循环,加了一直按下ESC键长点时间,执行多次showmessage
按键后再判断键弹起,再执行后面的模块.不要在FormKeyUp中实现
if Key=27 then
begin
while (GetKeyState(27)<>0) And (GetKeyState(27)<>1) do
begin
Application.ProcessMessages;
end;
aa;
end;aa过程中我也要判断ESC的状态,如果esc按时间长点,aa过程中马上就有消息
while True do
begin
if PeekMessage(Msg,0,WM_KEYFIRST,WM_KEYLAST,PM_REMOVE) then
begin
if msg.wParam=27 then
begin
...
Result:=1; exit;
end;
end;
Application.ProcessMessages;
......
end;
加Application.ProcessMessages;按下ESC键长点时间,执行多次showmessage还可理解,不加为什么是死循环?