如何制作适用于ipad的应用程序,使其成为Mac键盘 [英] How to go about making app for ipad that makes it into a Mac keyboard

查看:260
本文介绍了如何制作适用于ipad的应用程序,使其成为Mac键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图弄清楚如何创建一个具有按钮的应用程序,这些按钮会在按下时导致我的mac键入某个字符(或修饰符)。我已经准确地按下按钮了,所以我的项目现在离完成只有两步之遥:

I'm trying to figure out how to go about making an app that will have buttons that will when pressed cause my mac to key a certain character (or modifier). I've already got the buttons laid out exactly as a want them so my project is now just two steps away from being complete:


  1. 发送给mac的一条消息让它知道要按哪个键。

  2. 让mac按下实际键
    For 1 Im想要设置一个bonjour服务,它发送一个与在ipad上按下的键相关联的字符串。然后mac会收到这个。键盘上的一些键需要移位(即@)所以即时思考这个代码就像是S120。无论什么收到消息然后读取字符串,看它需要刺激移动按下与120相关的键。
    对于2,我的想法不多。请记住,这需要快速,因为它将是键盘。我正在考虑制作一个将接收字符串的iokit项目解码它并模拟正确的密钥。这可能有点过头了,我听说在处理内核时你必须要小心。如果我的想法不正确,请提出更好的方法并填写详细信息。谢谢!


推荐答案

至于模拟按键,使用Applescript可以轻松实现这一点。

As for simulating the keypress, there's an easy way to do this using Applescript.

tell application "System Events"
    keystroke "A"
end tell

(您可能需要在辅助功能前言中为辅助设备启用访问权限)。

(You might need to "enable access for assistive devices" in the Accessibility prefpane).

或者,可以在命令行上运行相同的脚本

Alternatively, the same script can be run on the command line

osascript -e 'tell app "System Events" to keystroke "a"' 

编辑:如果你'再担心速度,脚本桥可以提供帮助。

If you're worried about speed, the scripting bridge can help.

#import <Foundation/Foundation.h>
#import <ScriptingBridge/ScriptingBridge.h>

int main(int argc, char *argv[]) {
    @autoreleasepool {  
        id sysEvents = [SBApplication applicationWithBundleIdentifier: @"com.apple.systemevents"];

        [sysEvents keystroke: @"h" using: 'Ksft'];
        [sysEvents keystroke: @"e" using: 0];
        [sysEvents keystroke: @"l" using: 0];
        [sysEvents keystroke: @"l" using: 0];
        [sysEvents keystroke: @"o" using: 0];

        // keyCode might be more suitable for your purposes

        for (int i = 32; i < 64; i++) 
        {
            [sysEvents keyCode: i using: 0];    
        }
    }
}

你可以找到使用的密钥代码这个应用程序。

You can find key codes using this app.

http://manytricks.com/keycodes/

这篇关于如何制作适用于ipad的应用程序,使其成为Mac键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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