Delphi:如何检查是否按下了任何鼠标按钮-鼠标事件之外? [英] Delphi: How can I check if any mouse buttons are pressed - OUTSIDE of a mouse event?
问题描述
我有一个TDrawGrid,想要处理单击一个单元格并用鼠标滚轮滚动浏览单元格的方式略有不同:使用鼠标滚轮滚动时,视图应以所选单元格为中心,当简单单击一个单元格时,视图将不会移动(因为这会造成混乱)。
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).
使用鼠标滚轮滚动会触发 OnSelectCell
事件。单击一个单元格将首先触发 OnSelectCell
,然后触发 OnMouseDown
。因此,我需要确定 OnSelectCell
是否是通过鼠标单击触发的。 (我能想到的)最简单的方法是检查当前的鼠标按钮状态。
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
没有任何 TMouseButton
或 TShiftState
参数。那么如何查询鼠标按钮的状态呢?
OnSelectCell
doesn't come with any TMouseButton
or TShiftState
parameter. So how can I query the mouse-button state?
推荐答案
使用 GetKeyState
传递 VK_LBUTTON
来标识主要的鼠标按钮。如果返回值为负,则当系统生成导致触发 OnSelectCell
事件的输入消息时,该按钮将处于按下状态。
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.
这篇关于Delphi:如何检查是否按下了任何鼠标按钮-鼠标事件之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!