-
Notifications
You must be signed in to change notification settings - Fork 31
/
YLApplication.mm
92 lines (81 loc) · 4.07 KB
/
YLApplication.mm
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
//
// YLApplication.m
// MacBlueTelnet
//
// Created by Lan Yung-Luen on 11/17/07.
// Copyright 2007 yllan.org. All rights reserved.
//
#import "YLApplication.h"
#import "YLController.h"
static NSString *gLeftString, *gRightString;
@implementation YLApplication
+ (void) initialize
{
unichar r = NSRightArrowFunctionKey;
unichar l = NSLeftArrowFunctionKey;
gLeftString = [[NSString stringWithCharacters: &l length: 1] retain];
gRightString = [[NSString stringWithCharacters: &r length: 1] retain];
[NSColor setIgnoresAlpha: NO];
}
- (void) sendEvent: (NSEvent *)event
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
if ([event type] == NSKeyDown) {
if ((([event modifierFlags] & NSCommandKeyMask) == NSCommandKeyMask) &&
(([event modifierFlags] & NSShiftKeyMask) == NSShiftKeyMask) &&
[[event charactersIgnoringModifiers] isEqualToString: gRightString] ) {
event = [NSEvent keyEventWithType: [event type]
location: [event locationInWindow]
modifierFlags: [event modifierFlags] ^ NSShiftKeyMask
timestamp: [event timestamp]
windowNumber: [event windowNumber]
context: [event context]
characters: gRightString
charactersIgnoringModifiers: gRightString
isARepeat: [event isARepeat]
keyCode:[event keyCode]];
} else if ((([event modifierFlags] & NSCommandKeyMask) == NSCommandKeyMask) &&
(([event modifierFlags] & NSShiftKeyMask) == NSShiftKeyMask) &&
[[event charactersIgnoringModifiers] isEqualToString: gLeftString] ) {
event = [NSEvent keyEventWithType: [event type]
location: [event locationInWindow]
modifierFlags: [event modifierFlags] ^ NSShiftKeyMask
timestamp: [event timestamp]
windowNumber: [event windowNumber]
context: [event context]
characters: gLeftString
charactersIgnoringModifiers: gLeftString
isARepeat: [event isARepeat]
keyCode:[event keyCode]];
} else if (([event modifierFlags] & NSCommandKeyMask) == NSCommandKeyMask &&
([event modifierFlags] & NSAlternateKeyMask) == 0 &&
([event modifierFlags] & NSControlKeyMask) == 0 &&
([event modifierFlags] & NSShiftKeyMask) == 0 &&
[[event characters] intValue] > 0 &&
[[event characters] intValue] < 10) {
[_controller selectTabNumber: [[event characters] intValue]];
[pool release];
return;
} else if (([event modifierFlags] & NSCommandKeyMask) == NSCommandKeyMask &&
([event modifierFlags] & NSAlternateKeyMask) == 0 &&
([event modifierFlags] & NSControlKeyMask) == 0 &&
([event modifierFlags] & NSShiftKeyMask) == 0 &&
[[event characters] isEqualToString: @"r"] &&
[[NSUserDefaults standardUserDefaults] boolForKey: @"CommandRHotkey"]) {
[_controller reconnect: self];
[pool release];
return;
} else if (([event modifierFlags] & NSCommandKeyMask) == NSCommandKeyMask &&
([event modifierFlags] & NSAlternateKeyMask) == 0 &&
([event modifierFlags] & NSControlKeyMask) == 0 &&
([event modifierFlags] & NSShiftKeyMask) == 0 &&
[[event characters] isEqualToString: @"n"]) {
[_controller editSites: self];
[pool release];
return;
}
}
[super sendEvent:event];
[pool release];
}
@end