-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFanRadioApplication.m
60 lines (49 loc) · 1.21 KB
/
FanRadioApplication.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
//
// MyMediaApplication.m
// TestMediaKey
//
// Created by Du Song on 10-11-19.
// Copyright 2010 rollingcode.org. All rights reserved.
//
#import "FanRadioApplication.h"
#import "AppController.h"
#import <IOKit/hidsystem/ev_keymap.h>
@implementation FanRadioApplication
- (void) sendEvent:(NSEvent *)event
{
// Catch media key events
if ([event type] == NSSystemDefined && [event subtype] == 8)
{
int keyCode = (([event data1] & 0xFFFF0000) >> 16);
int keyFlags = ([event data1] & 0x0000FFFF);
int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
// Process the media key event and return
if ([self mediaKeyEvent:keyCode state:keyState]) return;
}
// Continue on to super
[super sendEvent:event];
}
- (BOOL) mediaKeyEvent:(int)key state:(BOOL)state
{
BOOL r = NO;
switch (key)
{
// Play pressed
case NX_KEYTYPE_PLAY:
if (state == NO)
r = [(AppController *)[self delegate] togglePlayPause:self];
break;
// Rewind
case NX_KEYTYPE_FAST:
if (state == YES)
r = [(AppController *)[self delegate] seekForward:self];
break;
// Previous
case NX_KEYTYPE_REWIND:
if (state == YES)
r = [(AppController *)[self delegate] seekBack:self];
break;
}
return r;
}
@end