Mega Code Archive

 
Categories / Delphi / Functions
 

The function Keypressed

Title: The function Keypressed Question: 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.