C#定时检测是否当前程序是否有人操作
发布网友
发布时间:2024-10-03 11:01
我来回答
共1个回答
热心网友
时间:2024-11-06 06:51
1:监视所有控件的鼠标操作,键盘操作
鼠标按下,鼠标双击,键盘按下
2:注册消息处理函数
private const int WM_KEYDOWN = 0x0100;
private const int WM_LBUTTONDOWN = 0x0201;
private const int WM_LBUTTONDBLCLK = 0x0203;
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
(PresentationSource.FromVisual(this) as HwndSource).AddHook(new HwndSourceHook(WndProc));
}
IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case WM_KEYDOWN:
case WM_LBUTTONDOWN:
case WM_LBUTTONDBLCLK:
break;
}
return hwnd;
}