-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tweak.x
56 lines (50 loc) · 1.29 KB
/
Tweak.x
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 <Foundation/Foundation.h>
#include <stdlib.h>
BOOL powerBtnPressed=NO;
int volumeupcount=0;
int volumedowncount=0;
struct __IOHIDEvent;
int32_t IOHIDEventGetType(struct __IOHIDEvent *event);
int IOHIDEventGetIntegerValue(struct __IOHIDEvent *event,long long value);
%hook BKButtonHIDEventProcessor
- (id)processEvent:(struct __IOHIDEvent **)event sender:(id)sender dispatcher:(id)dispatcher {
if(IOHIDEventGetType(*event)==3){ //3: Keyboard event
int usagePage=IOHIDEventGetIntegerValue(*event,196608LL);
int usage=IOHIDEventGetIntegerValue(*event,196609LL);
BOOL down=IOHIDEventGetIntegerValue(*event,196610LL)!=0;
if(usagePage==12){
if(usage==0x30){
powerBtnPressed=down;
if(!down){
volumeupcount=volumedowncount=0;
}
}else if(usage==0xe9){
if(down&&powerBtnPressed){
volumeupcount++;
if(volumedowncount==volumeupcount){
if(volumedowncount==1){
system("sbreload");
}else if(volumedowncount==2){
system("ldrestart");
}else if(volumedowncount==3){
exit(1);
}
}
if(volumedowncount!=0){
return nil;
}
}
}else if(usage==0xea){
if(down&&powerBtnPressed){
volumedowncount++;
if(volumeupcount!=0){
volumeupcount=0;
}
return nil;
}
}
}
}
return %orig;
}
%end