Funcao - keypressed (saber se uma tela esta pressionada) |
Top Previous Next |
|
if KeyPressed(VK_ALT) and KeyPressed(VK_CONTROL) then // teclas control e alt pressionadas
function KeyPressed(vk: Integer): Boolean; begin result := HiWord(GetKeyState(vk)) <> 0; end;
======================
How to realize the function KeyPressed... Answer:
This function should work with all Delphi versions:
function KeyPressed(aHandle: THandle): boolean; var Msg: TMsg; begin if PeekMessage(Msg, aHandle, WM_KEYFIRST,WM_KEYLAST, PM_REMOVE) then begin TranslateMessage(Msg); DispatchMessage(Msg); Result := true; end else Result := false; end;
Before useing this function you must empty the keyboard buffer. This works in one line:
while KeyPressed(Handle) do ;
As aHandle you have to use the form-handle. For the actual form it's 0. |