zoukankan
html css js c++ java
c#中通过设置钩子监视鼠标移动
这个问题来自论坛提问,C#的大致代码如下
using
System;
using
System.Windows.Forms;
using
System.Runtime.InteropServices;
namespace
WindowsApplication1
...
{
public
partial
class
Form1 : Form
...
{
public
Form1()
...
{
InitializeComponent();
}
private
void
Form1_Load(
object
sender, EventArgs e)
...
{
Win32Hook hook
=
new
Win32Hook();
hook.onMouseChange
+=
new
EventHandler(hook_onMouseChange);
hook.SetHook();
}
void
hook_onMouseChange(
object
sender, EventArgs e)
...
{
this
.Text
=
Cursor.Position.ToString();
}
}
public
class
Win32Hook
...
{
[DllImport(
"
kernel32
"
)]
public
static
extern
int
GetCurrentThreadId();
[DllImport(
"
user32
"
,CharSet
=
CharSet.Auto, CallingConvention
=
CallingConvention.StdCall)]
public
static
extern
int
SetWindowsHookEx(
HookType idHook,
HOOKPROC lpfn,
int
hmod,
int
dwThreadId);
public
enum
HookType
...
{
WH_GETMESSAGE
=
3
}
public
delegate
int
HOOKPROC(
int
nCode,
int
wParam,
int
lParam);
public
event
System.EventHandler onMouseChange;
public
void
SetHook()
...
{
SetWindowsHookEx(HookType.WH_GETMESSAGE,
new
HOOKPROC(
this
.MyKeyboardProc),
0
,
GetCurrentThreadId());
}
public
int
MyKeyboardProc(
int
nCode,
int
wParam,
int
lParam)
...
{
if
(onMouseChange
!=
null
)
...
{
onMouseChange(
null
,
null
);
}
return
0
;
}
}
}
查看全文
相关阅读:
【无旋转treap】模板
线性选择算法好题
【codeforces】305C GCD,容斥
双连通
线段树(3)
线段树(2)
线段树
2015 Multi-University Training Contest 2
2015 Multi-University Training Contest 1
Codeforces Round #302 (Div. 1)
原文地址:https://www.cnblogs.com/cl1024cl/p/6204956.html
最新文章
使用 GStreamer appsrc 等插件实现视频音频混流,录制和推流
GStreamer Windows tutorial demo 开发环境配置
SpringBoot+Mybatis+Freemark 最简单的例子
推荐几个不错的 java 教程和 HTML 教程
GStreamer 命令演示,音频视频播放及混流的演示 -- TerryHe
Spring Boot 入门例子 Hello world
Mac 安装 Gradle
Matrix对bitmap的一些操作
iListener:一个gsm的加强探测器发布
git的使用
热门文章
Ubuntu 10.04 (64bit)- error while loading shared libraries: libgtk-x11-2.0.so.0
在Ubuntu中用命令行(command line)打开PDF
openwrt 透明代理上网
上帝掷骰子
pthread_cond_wait , pthread_cond_signal
系统设计题分析
UNP 环境配置
B树、B+树、红黑树、skiplist
【某deed和某app面试】
给一个整数数列,修改最少的数使得严格递增
Copyright © 2011-2022 走看看