如何捕捉键盘和鼠标事件? [英] How to catch Keyboard and mouse events?

查看:279
本文介绍了如何捕捉键盘和鼠标事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个应用程序。当用户按下键盘上的特殊键或/和使用滚轮时,此应用程序必须执行某些操作。此应用程序是一项服务。它没有窗户。我想要抓住任何键盘或鼠标事件,这是用其他应用程序设计的。

I want to create an application. This application has to do something when a user presses special keys on keyboard or/and uses scroll wheel. This application is a service. It has no windows. I want to catch any keyboard or mouse events which were designed with other applications.

例如,您正在通过第三方应用程序观看电视。如果您按 Ctrl + Shift 并使用滚轮,我的应用程序会更改音量。

For example, you are watching TV by 3rd party application. If you press Ctrl + Shift and use scroll wheel my application changes the volume.

我使用Windows 7 x64 Visual Studio 2008。

I use Windows 7 x64 and Visual Studio 2008.

推荐答案

您可以致电 SetWindowsHookEx()在发生各种事件时通知。您可能想使用键盘钩子和鼠标钩子来观察鼠标事件。

You can call SetWindowsHookEx() to be notified when various events occur. You probably want to use the keyboard hook and the mouse hook to watch for mouse events.

这篇关于如何捕捉键盘和鼠标事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆