-
Notifications
You must be signed in to change notification settings - Fork 8
/
Key.m
141 lines (117 loc) · 3.19 KB
/
Key.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//
// Key.m
// ShowKeys
//
// Created by John Hobbs on 7/1/15.
// Copyright (c) 2015 John Hobbs. All rights reserved.
//
#import "Key.h"
@interface Key ()
@property NSString *characters;
@property bool shift;
@property bool command;
@property bool control;
@property bool alt;
@property NSString *representation;
@end
@implementation Key
- (id)init {
self = [super init];
_wipeBefore = NO;
_wipeAfter = NO;
return self;
}
- (id)initWithEvent:(NSEvent *)event {
self = [self init];
static NSArray *specialKeys;
if(! specialKeys) {
specialKeys = @[@36, @48, @51, @53, @114, @116, @117, @121, @123, @124, @125, @126];
}
NSMutableString *all = [[NSMutableString alloc] init];
self.shift = [event modifierFlags] & NSShiftKeyMask;
self.command = [event modifierFlags] & NSCommandKeyMask;
self.control = [event modifierFlags] & NSControlKeyMask;
if(self.shift && [specialKeys containsObject:[NSNumber numberWithUnsignedInt:[event keyCode]]]) {
_wipeBefore = YES;
[all appendString:@"SHIFT+"];
}
if([event modifierFlags] & NSCommandKeyMask) {
_wipeBefore = YES;
[all appendString:@"⌘+"];
}
if([event modifierFlags] & NSControlKeyMask) {
_wipeBefore = YES;
[all appendString:@"CTRL+"];
}
switch ([event keyCode]) {
case 36:
_wipeAfter = YES;
[all appendString:@"↵"];
break;
case 48:
[all appendString:@"[TAB]"];
break;
case 51:
_wipeAfter = YES;
[all appendString:@"⇤"];
break;
case 53:
[all appendString:@"[ESC]"];
break;
case 114:
[all appendString:@"[INS]"];
break;
case 116:
_wipeBefore = YES;
_wipeAfter = YES;
[all appendString:@"[PGUP]"];
break;
case 117:
_wipeBefore = YES;
_wipeAfter = YES;
[all appendString:@"[DEL]"];
break;
case 121:
_wipeBefore = YES;
_wipeAfter = YES;
[all appendString:@"[PGDN]"];
break;
case 123:
_wipeBefore = YES;
_wipeAfter = YES;
[all appendString:@"⬅"];
break;
case 124:
_wipeBefore = YES;
_wipeAfter = YES;
[all appendString:@"➡"];
break;
case 125:
_wipeBefore = YES;
_wipeAfter = YES;
[all appendString:@"⬇"];
break;
case 126:
_wipeBefore = YES;
_wipeAfter = YES;
[all appendString:@"⬆"];
break;
default:
[all appendString:[event charactersIgnoringModifiers]];
break;
}
self.representation = all;
return self;
}
- (id)initWithTest {
self = [self init];
self.representation = @"== TEST ==";
return self;
}
- (NSInteger)length {
return [self.representation length];
}
- (NSString *)stringValue {
return self.representation;
}
@end