Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi: How can I check if any mouse buttons are pressed - OUTSIDE of a mouse event?

I have a TDrawGrid and want to handle clicking on a cell and scrolling through cells with the mouse wheel slightly differently: When scrolling with the mouse wheel, the view shall center on the selected cell, when simply clicking on a cell, the view shall not move (because that'd be confusing).

Scrolling with the mouse wheel fires the OnSelectCell event. Clicking on a cell FIRST fires OnSelectCell, followed by OnMouseDown. So I need to figure out if OnSelectCell was triggered by a mouse click. Easiest way to do (that I can think of) would be to check the current mouse-button state.

OnSelectCell doesn't come with any TMouseButton or TShiftState parameter. So how can I query the mouse-button state?

like image 235
Robin Avatar asked Sep 05 '14 08:09

Robin


1 Answers

Use GetKeyState passing VK_LBUTTON to identify the primary mouse button. If the return value is negative, the button was down when the system generated the input message that led to the OnSelectCell event being fired.

like image 159
David Heffernan Avatar answered Oct 22 '22 03:10

David Heffernan