实时按键检测? [英] Real Time Key Press Detection?

查看:112
本文介绍了实时按键检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以实时检测按键并启动操作?我想要做的基本上是...如果用户正在输入文档,并使用快捷键Ctrl + Shift +>增加字体大小,我希望VBA检测按键
并播放一个声音。每次切换增加字体大小的键时都会出现这种情况。这是VBA的实时检测吗?

Is it possible to detect a key press and initiate an action, in real time? What I am trying to do is basically... if a user is typing in a document, and increases the font size using the shortcut key Ctrl+Shift+>, I want VBA to detect the key press and play a sound. This should occur every time the key to increase the font size is toggled. Is this real time detection possible with VBA?

推荐答案

有一种方法,但它取决于您使用的应用程序。

There is a way, but it depends on application you are using.

Excel有一个很好的
OnKey方法
,所以你要做的就是运行:

Excel has a nice OnKey method, so all you have to do is run this:

Application.OnKey" + ^ I"," Module1.ABC"

Application.OnKey "+^I", "Module1.ABC"

并将您的代码放在链接过程中(示例中为子ABC)。

and put your code in linked procedure (sub ABC in the example).

但是Word例如不支持OnKey方法,所以捕获键击(我知道)的唯一方法是使用Windows钩子。你可以找到有关钩子的信息
这里,但是在这个论坛上也有一些讨论和示例代码。

However Word for example does not support OnKey method, so the only way to capture key strokes (that I know of) would be using windows hooks. You can find info on hooks here, but there are also some discussions and sample codes on this forum.


这篇关于实时按键检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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