Search code examples
windowsdelphiwinapidelphi-7

Detect if Mouse button already pressed before form shows


If a mouse button is pressed and a window is shown that window will receive the MouseUp event when the mouse button is released.

Is it possible to detect, once the window is shown, whether or not a mouse button is already pressed?


Solution

  • I would try this:

    procedure TForm1.FormShow(Sender: TObject);
    begin
      if GetKeyState(VK_LBUTTON) and $8000 <> 0 then
        ShowMessage('Left mouse button is pressed...')
      else
        ShowMessage('Left mouse button is not pressed...')
    end;