本文介绍了如何模拟在OS X低一级重点preSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成键盘的keydown和编程KEYUP事件。我目前使用CGPostKeyboardEvent要做到这一点,但是我正在寻找这样做的方式在一个较低的水平。我已经看过DDHidLib但不能想出一个办法来创建一个假的事件。谁能帮助?

I am trying to generate keyboard keydown and keyup events programmatically. I am currently using CGPostKeyboardEvent to do this, but I am searching for a way to do this at a lower level. I have looked at DDHidLib but could not figure out a way to create a fake event. Can anyone help?

更新
由于weichsel的意见,我现在正在创建具有以下关键down事件:

update: Thanks to weichsel's advice I am now creating a key down event with the following:

  CGEventRef e = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)52, true);
  CGEventPost(kCGSessionEventTap, e);
  CFRelease(e);

我发现 href=\"http://www.openframeworks.cc/forum/viewtopic.php?f=9&t=2267\">。

which I found here.

然而,我的问题仍然有效,所以我会详细一点。我想发送键presses来实现键捕获功能:

However, my problem still stands so I will elaborate a bit. The application (3rd party) that I would like to send keypresses to implements DDHidLib's key capturing function:

- (void) ddhidKeyboard: (DDHidKeyboard *) keyboard
			 keyDown: (unsigned) usageId;

和这永远不会使用当前的方法被调用。我的猜测是,与CGEventCreateKeyboardEvent下模拟的关键是在过高的水平,由ddhidKeyboard捕获:KEYDOWN。所以,我所要做的是在足够低的水平,这样它将被ddhidKeyboard识别创建keydown事件:KEYDOWN。

And this never gets called using the current method. My guess is that the key down simulated with CGEventCreateKeyboardEvent is at too high of a level to be captured by ddhidKeyboard:keyDown. So what I am trying to do is create the keydown event at a sufficiently low level such that it will be recognized by ddhidKeyboard:keyDown.

推荐答案

这有什么错Quartz事件服务?结果
我认为你是正确的轨道上,但你应该使用<$c$c>CGEventCreateKeyboardEvent而不是 CGPostKeyboardEvent ,因为后者是因为Mac OS X 10.6 pcated德$ P $。

What's wrong with Quartz Event Services?
I think you are on the right track, but you should use CGEventCreateKeyboardEvent instead of CGPostKeyboardEvent because the latter is deprecated since Mac OS X 10.6.

这篇关于如何模拟在OS X低一级重点preSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 11:54