[英]detect if mouse's back/forward button was pressed
How can I use GetKeyState to detect if the mouse's back or forward button is down when I receive a mouse event? 收到鼠标事件时,如何使用GetKeyState检测鼠标的后退或前进按钮是否按下? MSDN's virtual key code list seems to define only left, right and middle mouse buttons. MSDN的虚拟键代码列表似乎仅定义了鼠标左键,右键和中键。
Callback method that is passed to SetWindowsHookEx: 传递给SetWindowsHookEx的回调方法:
[MethodImpl(MethodImplOptions.NoInlining)]
private IntPtr LowLevelMouseProc(int nCode, UIntPtr wParam, IntPtr lParam)
{
Debug.WriteLine(wParam.ToUInt32());
Debug.WriteLine("MK_XBUTTON1: " + (wParam.ToUInt32() & 0x20));
Debug.WriteLine("MK_XBUTTON2: " + (wParam.ToUInt32() & 0x40));
}
Outputs the following when either back or forward is pressed: 按下后退或前进时输出以下内容:
523
MK_XBUTTON1: 0
MK_XBUTTON2: 0
524
MK_XBUTTON1: 0
MK_XBUTTON2: 0
You were linking to the Windows CE documentation. 您已链接到Windows CE文档。 The Desktop Windows documentation for Virtual-Key Codes contains the VK_XBUTTON1
and VK_XBUTTON2
codes. 桌面Windows 虚拟密钥代码文档包含VK_XBUTTON1
和VK_XBUTTON2
代码。 Those are the constants for the additional mouse buttons, that are often assigned to forward and backward navigation. 这些是其他鼠标按钮的常量,这些常量通常分配给前进和后退导航。
If you want to handle the X button messages immediately, they are posted to your application using WM_XBUTTONDOWN
and WM_XBUTTONUP
. 如果要立即处理X按钮消息,请使用WM_XBUTTONDOWN
和WM_XBUTTONUP
将它们发布到您的应用程序中。 The low-order word of wParam
indicates which X button is down (if any). wParam
的低位字指示哪个X按钮按下(如果有)。
Assume you use C# WinForm, and what you want is: When the picture box is focused , detect if mouse's back/forward button was pressed. 假设您使用C#WinForm,并且想要的是:当图片框被聚焦时 ,检测是否按下了鼠标的后退/前进按钮。
private System.Windows.Forms.PictureBox picContent;
this.picContent.MouseDown += new System.Windows.Forms.MouseEventHandler(this.picContent_MouseDown);
private void picContent_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.XButton1)
MessageBox.Show("Back");
if (e.Button == MouseButtons.XButton2)
MessageBox.Show("Forward");
}
Tested on .Net Framework 4.5.2 在.Net Framework 4.5.2上测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.