-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyNSApplication.m
56 lines (50 loc) · 2.22 KB
/
MyNSApplication.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// MyNSApplication.m
// Lutrin
//
// Created by Shigeru Hagiwara on 2014/06/29.
//
//
#import "MyNSApplication.h"
@implementation MyNSApplication
- (void)sendEvent:(NSEvent *) event
{
if ([event type] == NSKeyDown) {
// キーイベントを書き換えます。
// スペースキー → 右矢印キー
// j → 右矢印キー
// k → 左矢印キー
const unichar right[1] = { NSRightArrowFunctionKey };
const unichar left[1] = { NSLeftArrowFunctionKey };
NSString *rightChars = [NSString stringWithCharacters:right length:1];
NSString *leftChars = [NSString stringWithCharacters:left length:1];
if( [[event charactersIgnoringModifiers] isEqualToString:@" "] ||
[[event charactersIgnoringModifiers] isEqualToString:@"j"] ) {
event = [NSEvent keyEventWithType:[event type]
location:[event locationInWindow]
modifierFlags:[event modifierFlags]
timestamp:[event timestamp]
windowNumber:[event windowNumber]
context:[event context]
characters:rightChars
charactersIgnoringModifiers:rightChars
isARepeat:[event isARepeat]
keyCode:124 // Right key
];
} else if( [[event charactersIgnoringModifiers] isEqualToString:@"k"] ) {
event = [NSEvent keyEventWithType:[event type]
location:[event locationInWindow]
modifierFlags:[event modifierFlags]
timestamp:[event timestamp]
windowNumber:[event windowNumber]
context:[event context]
characters:leftChars
charactersIgnoringModifiers:leftChars
isARepeat:[event isARepeat]
keyCode:123 // Left key
];
}
}
[super sendEvent:event];
}
@end