问题描述
是否可以实时检测按键并启动操作?我想要做的基本上是...如果用户正在输入文档,并使用快捷键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?
推荐答案
Excel有一个很好的,所以你要做的就是运行:
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 hookshere, but there are also some discussions and sample codes on this forum.
这篇关于实时按键检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!