This repository was archived by the owner on Dec 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhKC.m
More file actions
executable file
·56 lines (52 loc) · 1.56 KB
/
hKC.m
File metadata and controls
executable file
·56 lines (52 loc) · 1.56 KB
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
#import <Cocoa/Cocoa.h>
#import "tbv.h"
#import "Functions.h"
@implementation hKC : NSTextField
- (BOOL) textShouldBeginEditing:(NSText *)t {
NSBeep();
[self flagsChanged:nil];
return NO;
}
- (void) flagsChanged:(NSEvent *)e {
[self setStringValue:[NSPrefPaneUtils stringForModifiers:[e modifierFlags]]];
int g = _CGSDefaultConnection();
CGSSetGlobalHotKeyOperatingMode(g, CGSGlobalHotKeyDisable);
BOOL c = YES;
do {
e = [NSApp nextEventMatchingMask:NSFlagsChangedMask|NSKeyDownMask|NSLeftMouseDownMask untilDate:[NSDate dateWithTimeIntervalSinceNow:10.0] inMode:NSDefaultRunLoopMode dequeue:YES];
switch ([e type]) {
case NSFlagsChanged:
[self setStringValue:[NSPrefPaneUtils stringForModifiers:[e modifierFlags]]];
break;
case NSKeyDown: {
c = NO;
unsigned short k = [e keyCode];
if ([e modifierFlags] & (NSCommandKeyMask | NSControlKeyMask | NSAlternateKeyMask)) {
M = [e modifierFlags];
K = k;
// } else if(k == 51 || k == 117) { // Delete (<) or Delete (>)
// M = 0; K = 0;
} else if (k == 48 || k == 53) { // Esc is 53, Tab is 48
if ([e modifierFlags] & NSShiftKeyMask) {
[[self window] selectKeyViewPrecedingView:self];
goto fin;
}
} else {
NSBeep();
c = YES;
}
break;
}
case NSLeftMouseDown:
[NSApp postEvent:e atStart:YES]; // fall through
default:
c = NO;
}
} while (c);
[[self window] selectKeyViewFollowingView:self];
fin:
CGSSetGlobalHotKeyOperatingMode(g, CGSGlobalHotKeyEnable);
NSString *t = M ? s4km(M,K) : @"";
[self setStringValue:t];
}
@end