From 815bf3e8601b6d0cfb0296c6f2c302aaf5059b23 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 28 Aug 2018 08:19:02 +0200 Subject: HeadphoneKey: Press keys from `_key_buffer` map Take the headphone keys in `_key_buffer` and get the associated map action by calling into the Rust library. If the map action has `MapKind::Map`, then we need to simulate key presses of the characters in the `action` field. Works, but it's a little finicky. Maybe I'm including the null byte in the loop? --- DomeKey/HeadphoneKey.h | 1 + DomeKey/HeadphoneKey.m | 15 +++++++++++++++ DomeKey/KeyboardSimulator.m | 1 + 3 files changed, 17 insertions(+) diff --git a/DomeKey/HeadphoneKey.h b/DomeKey/HeadphoneKey.h index 2a74fc1..22e7238 100644 --- a/DomeKey/HeadphoneKey.h +++ b/DomeKey/HeadphoneKey.h @@ -10,6 +10,7 @@ #import #import "dome_key_map.h" +#import "KeyboardSimulator.h" typedef enum KeyPress : BOOL { KeyPressDown = YES, diff --git a/DomeKey/HeadphoneKey.m b/DomeKey/HeadphoneKey.m index 1d815b2..e955128 100644 --- a/DomeKey/HeadphoneKey.m +++ b/DomeKey/HeadphoneKey.m @@ -67,6 +67,21 @@ { NSLog(@"%@", _key_buffer); + NSUInteger count = [_key_buffer count]; + HeadphoneButton trigger[count]; + + for (int i = 0; i < count; i++) { + trigger[i] = (HeadphoneButton)[[_key_buffer objectAtIndex:i] intValue]; + } + + const CKeyActionResult *result = c_run_key_action(trigger, count); + + if (*result->kind == MapKind_Map) { + for (int i = 0; i < strlen(result->action); i++) { + [KeyboardSimulator simpleKeyPressWithKey:result->action[i]]; + } + } + [_key_buffer removeAllObjects]; } diff --git a/DomeKey/KeyboardSimulator.m b/DomeKey/KeyboardSimulator.m index 1465920..6e9d38e 100644 --- a/DomeKey/KeyboardSimulator.m +++ b/DomeKey/KeyboardSimulator.m @@ -18,6 +18,7 @@ NSNumber *key_number = charToKeyCode(aChar); if (key_number == nil) { + NSLog(@"charToKeyCode returned nil"); return; } CGKeyCode key_code = (CGKeyCode)[key_number intValue]; -- cgit v1.2.3