]> git.saurik.com Git - veency.git/commitdiff
Implement keys with IOHIDEventCreateKeyboardEvent.
authorJay Freeman (saurik) <saurik@saurik.com>
Mon, 27 Jan 2014 04:42:27 +0000 (20:42 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Mon, 27 Jan 2014 04:42:27 +0000 (20:42 -0800)
.gitignore
Tweak.mm
include/IOKit/hid [new symlink]
include/IOKit/hidsystem [new symlink]
makefile

index 2d24ca800fb99733f43aa2a4db0d70f531b28c21..d43f5013eab78052e2c2faaf274d5ceaeffa9e32 100644 (file)
@@ -5,3 +5,5 @@ _
 jpeg-9a
 libjpeg.arm*
 libvncserver.arm*
 jpeg-9a
 libjpeg.arm*
 libvncserver.arm*
+IOHIDFamily-503.1.13
+xnu-2422.1.72
index 807022ff93abada61b5e77bcf62f2d9f78c289ba..7eaaea9c5f0e064379e37ccb0b797d3b4b0dc97f 100644 (file)
--- a/Tweak.mm
+++ b/Tweak.mm
@@ -32,6 +32,8 @@
 #include <rfb/keysym.h>
 
 #include <mach/mach.h>
 #include <rfb/keysym.h>
 
 #include <mach/mach.h>
+#include <mach/mach_time.h>
+
 #include <sys/mman.h>
 #include <sys/sysctl.h>
 
 #include <sys/mman.h>
 #include <sys/sysctl.h>
 
@@ -43,6 +45,9 @@
 #import <Foundation/Foundation.h>
 #import <UIKit/UIKit.h>
 
 #import <Foundation/Foundation.h>
 #import <UIKit/UIKit.h>
 
+#include <IOKit/hid/IOHIDEventTypes.h>
+#include <IOKit/hidsystem/IOHIDUsageTables.h>
+
 extern "C" {
 #include "SpringBoardAccess.h"
 }
 extern "C" {
 #include "SpringBoardAccess.h"
 }
@@ -122,6 +127,16 @@ extern "C" kern_return_t IOMobileFramebufferSwapSetLayer(
 extern "C" void IOMobileFramebufferGetDisplaySize(IOMobileFramebufferRef connect, CGSize *size);
 extern "C" void IOMobileFramebufferIsMainDisplay(IOMobileFramebufferRef connect, int *main);
 
 extern "C" void IOMobileFramebufferGetDisplaySize(IOMobileFramebufferRef connect, CGSize *size);
 extern "C" void IOMobileFramebufferIsMainDisplay(IOMobileFramebufferRef connect, int *main);
 
+typedef CFTypeRef IOHIDEventRef;
+typedef CFTypeRef IOHIDEventSystemClientRef;
+
+extern "C" {
+    IOHIDEventRef IOHIDEventCreateKeyboardEvent(CFAllocatorRef allocator, uint64_t time, uint16_t page, uint16_t usage, Boolean down, IOHIDEventOptionBits flags);
+    IOHIDEventSystemClientRef IOHIDEventSystemClientCreate(CFAllocatorRef allocator);
+    void IOHIDEventSetSenderID(IOHIDEventRef event, uint64_t sender);
+    void IOHIDEventSystemClientDispatchEvent(IOHIDEventSystemClientRef client, IOHIDEventRef event);
+}
+
 static size_t width_;
 static size_t height_;
 static NSUInteger ratio_ = 0;
 static size_t width_;
 static size_t height_;
 static NSUInteger ratio_ = 0;
@@ -571,13 +586,110 @@ static void VNCPointerOld(int buttons, int x, int y, CGPoint location, int diff,
         mach_port_deallocate(mach_task_self(), purple);
 }
 
         mach_port_deallocate(mach_task_self(), purple);
 }
 
+static void VNCSendHIDEvent(IOHIDEventRef event) {
+    static IOHIDEventSystemClientRef client_(NULL);
+    if (client_ == NULL)
+        client_ = IOHIDEventSystemClientCreate(kCFAllocatorDefault);
+    IOHIDEventSetSenderID(event, 0xDEFACEDBEEFFECE5);
+
+    IOHIDEventSystemClientDispatchEvent(client_, event);
+    CFRelease(event);
+}
+
 static void VNCPointerNew(int buttons, int x, int y, CGPoint location, int diff, bool twas, bool tis) {
 static void VNCPointerNew(int buttons, int x, int y, CGPoint location, int diff, bool twas, bool tis) {
+    if ((diff & 0x10) != 0)
+        VNCSendHIDEvent(IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault, mach_absolute_time(), kHIDPage_Telephony, kHIDUsage_Tfon_Flash, (buttons & 0x10) != 0, 0));
+    if ((diff & 0x04) != 0)
+        VNCSendHIDEvent(IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault, mach_absolute_time(), kHIDPage_Consumer, kHIDUsage_Csmr_Menu, (buttons & 0x04) != 0, 0));
+    if ((diff & 0x02) != 0)
+        VNCSendHIDEvent(IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault, mach_absolute_time(), kHIDPage_Consumer, kHIDUsage_Csmr_Power, (buttons & 0x02) != 0, 0));
+
+    if (twas != tis || tis) {
+    }
 }
 
 GSEventRef (*$GSEventCreateKeyEvent)(int, CGPoint, CFStringRef, CFStringRef, id, UniChar, short, short);
 GSEventRef (*$GSCreateSyntheticKeyEvent)(UniChar, BOOL, BOOL);
 
 }
 
 GSEventRef (*$GSEventCreateKeyEvent)(int, CGPoint, CFStringRef, CFStringRef, id, UniChar, short, short);
 GSEventRef (*$GSCreateSyntheticKeyEvent)(UniChar, BOOL, BOOL);
 
+static void VNCKeyboardNew(rfbBool down, rfbKeySym key, rfbClientPtr client) {
+    //NSLog(@"VNC d:%u k:%04x", down, key);
+
+    uint16_t usage;
+
+    switch (key) {
+        case XK_A: case XK_a: usage = kHIDUsage_KeyboardA; break;
+        case XK_B: case XK_b: usage = kHIDUsage_KeyboardB; break;
+        case XK_C: case XK_c: usage = kHIDUsage_KeyboardC; break;
+        case XK_D: case XK_d: usage = kHIDUsage_KeyboardD; break;
+        case XK_E: case XK_e: usage = kHIDUsage_KeyboardE; break;
+        case XK_F: case XK_f: usage = kHIDUsage_KeyboardF; break;
+        case XK_G: case XK_g: usage = kHIDUsage_KeyboardG; break;
+        case XK_H: case XK_h: usage = kHIDUsage_KeyboardH; break;
+        case XK_I: case XK_i: usage = kHIDUsage_KeyboardI; break;
+        case XK_J: case XK_j: usage = kHIDUsage_KeyboardJ; break;
+        case XK_K: case XK_k: usage = kHIDUsage_KeyboardK; break;
+        case XK_L: case XK_l: usage = kHIDUsage_KeyboardL; break;
+        case XK_M: case XK_m: usage = kHIDUsage_KeyboardM; break;
+        case XK_N: case XK_n: usage = kHIDUsage_KeyboardN; break;
+        case XK_O: case XK_o: usage = kHIDUsage_KeyboardO; break;
+        case XK_P: case XK_p: usage = kHIDUsage_KeyboardP; break;
+        case XK_Q: case XK_q: usage = kHIDUsage_KeyboardQ; break;
+        case XK_R: case XK_r: usage = kHIDUsage_KeyboardR; break;
+        case XK_S: case XK_s: usage = kHIDUsage_KeyboardS; break;
+        case XK_T: case XK_t: usage = kHIDUsage_KeyboardT; break;
+        case XK_U: case XK_u: usage = kHIDUsage_KeyboardU; break;
+        case XK_V: case XK_v: usage = kHIDUsage_KeyboardV; break;
+        case XK_W: case XK_w: usage = kHIDUsage_KeyboardW; break;
+        case XK_X: case XK_x: usage = kHIDUsage_KeyboardX; break;
+        case XK_Y: case XK_y: usage = kHIDUsage_KeyboardY; break;
+        case XK_Z: case XK_z: usage = kHIDUsage_KeyboardZ; break;
+
+        case XK_underscore: case XK_minus: usage = kHIDUsage_KeyboardHyphen; break;
+        case XK_plus: case XK_equal: usage = kHIDUsage_KeyboardEqualSign; break;
+        case XK_braceleft: case XK_bracketleft: usage = kHIDUsage_KeyboardOpenBracket; break;
+        case XK_braceright: case XK_bracketright: usage = kHIDUsage_KeyboardCloseBracket; break;
+        case XK_bar: case XK_backslash: usage = kHIDUsage_KeyboardBackslash; break;
+        case XK_colon: case XK_semicolon: usage = kHIDUsage_KeyboardSemicolon; break;
+        case XK_quotedbl: case XK_apostrophe: usage = kHIDUsage_KeyboardQuote; break;
+        case XK_asciitilde: case XK_grave: usage = kHIDUsage_KeyboardGraveAccentAndTilde; break;
+        case XK_less: case XK_comma: usage = kHIDUsage_KeyboardComma; break;
+        case XK_greater: case XK_period: usage = kHIDUsage_KeyboardPeriod; break;
+        case XK_question: case XK_slash: usage = kHIDUsage_KeyboardSlash; break;
+
+        case XK_Return: usage = kHIDUsage_KeyboardReturnOrEnter; break;
+        case XK_BackSpace: usage = kHIDUsage_KeyboardDeleteOrBackspace; break;
+        case XK_Tab: usage = kHIDUsage_KeyboardTab; break;
+        case XK_space: usage = kHIDUsage_KeyboardSpacebar; break;
+
+        case XK_Shift_L: usage = kHIDUsage_KeyboardLeftShift; break;
+        case XK_Shift_R: usage = kHIDUsage_KeyboardRightShift; break;
+        case XK_Control_L: usage = kHIDUsage_KeyboardLeftControl; break;
+        case XK_Control_R: usage = kHIDUsage_KeyboardRightControl; break;
+        case XK_Meta_L: usage = kHIDUsage_KeyboardLeftAlt; break;
+        case XK_Meta_R: usage = kHIDUsage_KeyboardRightAlt; break;
+        case XK_Alt_L: usage = kHIDUsage_KeyboardLeftGUI; break;
+        case XK_Alt_R: usage = kHIDUsage_KeyboardRightGUI; break;
+
+        case XK_Up: usage = kHIDUsage_KeyboardUpArrow; break;
+        case XK_Down: usage = kHIDUsage_KeyboardDownArrow; break;
+        case XK_Left: usage = kHIDUsage_KeyboardLeftArrow; break;
+        case XK_Right: usage = kHIDUsage_KeyboardRightArrow; break;
+
+        case XK_Home: case XK_Begin: usage = kHIDUsage_KeyboardHome; break;
+        case XK_End: usage = kHIDUsage_KeyboardEnd; break;
+        case XK_Page_Up: usage = kHIDUsage_KeyboardPageUp; break;
+        case XK_Page_Down: usage = kHIDUsage_KeyboardPageDown; break;
+
+        default: return;
+    }
+
+    VNCSendHIDEvent(IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault, mach_absolute_time(), kHIDPage_KeyboardOrKeypad, usage, down, 0));
+}
+
 static void VNCKeyboard(rfbBool down, rfbKeySym key, rfbClientPtr client) {
 static void VNCKeyboard(rfbBool down, rfbKeySym key, rfbClientPtr client) {
+    if (kCFCoreFoundationVersionNumber >= 800)
+        return VNCKeyboardNew(down, key, client);
+
     if (!down)
         return;
 
     if (!down)
         return;
 
diff --git a/include/IOKit/hid b/include/IOKit/hid
new file mode 120000 (symlink)
index 0000000..9ce08c2
--- /dev/null
@@ -0,0 +1 @@
+../../IOHIDFamily-503.1.13/IOHIDFamily
\ No newline at end of file
diff --git a/include/IOKit/hidsystem b/include/IOKit/hidsystem
new file mode 120000 (symlink)
index 0000000..9ce08c2
--- /dev/null
@@ -0,0 +1 @@
+../../IOHIDFamily-503.1.13/IOHIDFamily
\ No newline at end of file
index ff6cd4346d6a3020760a168357603b6a24458eb2..bab6125dbaca9e24039c694e9b29897c66fb47a5 100644 (file)
--- a/makefile
+++ b/makefile
@@ -14,10 +14,15 @@ Veency_FRAMEWORKS += IOMobileFramebuffer
 Veency_FRAMEWORKS += QuartzCore
 Veency_FRAMEWORKS += UIKit
 
 Veency_FRAMEWORKS += QuartzCore
 Veency_FRAMEWORKS += UIKit
 
+ADDITIONAL_LDFLAGS += -weak_framework IOKit
+
 ADDITIONAL_OBJCFLAGS += -Wno-gnu
 ADDITIONAL_OBJCFLAGS += -Wno-dangling-else
 
 ADDITIONAL_OBJCFLAGS += -Wno-gnu
 ADDITIONAL_OBJCFLAGS += -Wno-dangling-else
 
-ADDITIONAL_OBJCFLAGS += -idirafter .
+ADDITIONAL_OBJCFLAGS += -idirafter xnu-2422.1.72/iokit
+ADDITIONAL_OBJCFLAGS += -idirafter xnu-2422.1.72/libkern
+ADDITIONAL_OBJCFLAGS += -idirafter xnu-2422.1.72/osfmk
+ADDITIONAL_OBJCFLAGS += -idirafter include
 
 ADDITIONAL_OBJCFLAGS += -Ilibvncserver
 ADDITIONAL_OBJCFLAGS += -Xarch_armv6 -Ilibvncserver.armv6
 
 ADDITIONAL_OBJCFLAGS += -Ilibvncserver
 ADDITIONAL_OBJCFLAGS += -Xarch_armv6 -Ilibvncserver.armv6