c#鼠标钩子问题
从网上找来的代码,程序已能获取鼠标坐标,其他就没别的功能了,我想实现单击鼠标左键就变成单击了右键,怎么写?换个问法吧,就说鼠标钩子怎么捕获鼠标单击事件???[Struct...
从网上找来的代码,程序已能获取鼠标坐标,其他就没别的功能了,我想实现单击鼠标左键就变成单击了右键,怎么写?
换个问法吧,就说鼠标钩子怎么捕获鼠标单击事件???
[StructLayout(LayoutKind.Sequential)]
public class POINT
{
public int x;
public int y;
}
[StructLayout(LayoutKind.Sequential)]
public class MouseHookStruct
{
public POINT pt;
public int hwnd;
public int wHitTestCode;
public int dwExtraInfo;
} 展开
换个问法吧,就说鼠标钩子怎么捕获鼠标单击事件???
[StructLayout(LayoutKind.Sequential)]
public class POINT
{
public int x;
public int y;
}
[StructLayout(LayoutKind.Sequential)]
public class MouseHookStruct
{
public POINT pt;
public int hwnd;
public int wHitTestCode;
public int dwExtraInfo;
} 展开
展开全部
用mouse_event发送鼠标右键事件。
如果仅是恶作剧的话,修改右手鼠标为左手鼠标就行了。鼠标钩子,八成会被杀毒软件干掉。
[DllImport("user32.dll")]
static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
enum MouseEventFlag : uint
{
Move = 0x0001,
LeftDown = 0x0002,
LeftUp = 0x0004,
RightDown = 0x0008,
RightUp = 0x0010,
MiddleDown = 0x0020,
MiddleUp = 0x0040,
XDown = 0x0080,
XUp = 0x0100,
Wheel = 0x0800,
VirtualDesk = 0x4000,
Absolute = 0x8000
}
如果仅是恶作剧的话,修改右手鼠标为左手鼠标就行了。鼠标钩子,八成会被杀毒软件干掉。
[DllImport("user32.dll")]
static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
enum MouseEventFlag : uint
{
Move = 0x0001,
LeftDown = 0x0002,
LeftUp = 0x0004,
RightDown = 0x0008,
RightUp = 0x0010,
MiddleDown = 0x0020,
MiddleUp = 0x0040,
XDown = 0x0080,
XUp = 0x0100,
Wheel = 0x0800,
VirtualDesk = 0x4000,
Absolute = 0x8000
}
追问
你这个只能模拟鼠标事件啊,比如
mouse_event(MouseEventFlag.LeftDown | MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
我问的是怎么“捕获”鼠标事件,程序得知道我什么时候按了右键。。。
例如:
if(捕获到鼠标右键)
{
mouse_event(MouseEventFlag.LeftDown | MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);
}
追答
看你抓住坐标,还以为你顺便把点击也搞定了呢。
网上有个鼠标键盘钩子的类。你找找吧。直接对鼠标点击事件编程就行了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询