diff options
author | Teddy Wing | 2018-08-28 08:19:02 +0200 |
---|---|---|
committer | Teddy Wing | 2018-08-28 08:25:05 +0200 |
commit | 815bf3e8601b6d0cfb0296c6f2c302aaf5059b23 (patch) | |
tree | 8c13b2495cb4e98b1b66d137ad04f4d5bd298e64 | |
parent | 56caca057584ae08df0de632f216933b2740708f (diff) | |
download | DomeKey-815bf3e8601b6d0cfb0296c6f2c302aaf5059b23.tar.bz2 |
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?
-rw-r--r-- | DomeKey/HeadphoneKey.h | 1 | ||||
-rw-r--r-- | DomeKey/HeadphoneKey.m | 15 | ||||
-rw-r--r-- | DomeKey/KeyboardSimulator.m | 1 |
3 files changed, 17 insertions, 0 deletions
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 <DDHidLib/DDHidAppleMikey.h> #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]; |