failed attempts to intercept copy command when the cursor is in the empty text field...
[LeanCalc.git] / Sources / CmdKeyInterceptApplication.m
1 //
2 //  CmdKeyInterceptApplication.m
3 //  LeanCalc
4 //
5 //  Created by Marc Liyanage on 13.02.05.
6 //  Copyright 2005 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "CmdKeyInterceptApplication.h"
10
11
12 @implementation CmdKeyInterceptApplication
13
14 - (void)sendEvent:(NSEvent *)event {
15         
16         if ([event type] != NSKeyDown) {
17                 [super sendEvent:event];
18                 return;
19         }
20         
21         /* Look at the top 16 bits, only intercept
22         * key down events whose only modifier is the command key */
23         if (([event modifierFlags] & 0xffff0000) != NSCommandKeyMask) {
24                 [super sendEvent:event];
25                 return;
26         }
27         
28         int index = [[event characters] intValue];
29         if (index > 9 || index < 1) {
30                 [super sendEvent:event];
31                 return;
32         }
33         
34         [self sendAction:@selector(insertPrevious:) to:nil from:[NSNumber numberWithInt:index]];
35
36 }
37
38 @end