Skip to content

Commit

Permalink
Merge branch 'release/1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
sunghyuk committed Jul 13, 2016
2 parents 9114a66 + 60a2f7a commit 76268b4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
1 change: 1 addition & 0 deletions d3key/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

@property (strong) MainWindowController *windowController;
@property (strong, nonatomic) IBOutlet NSMenu *statusMenu;
@property (strong, nonatomic) IBOutlet NSMenuItem *aboutMenuItem;
@property (strong, nonatomic) NSStatusItem *statusBar;

- (IBAction)statusPreferences:(id)sender;
Expand Down
42 changes: 32 additions & 10 deletions d3key/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ - (void) awakeFromNib {

self.statusBar.menu = self.statusMenu;
self.statusBar.highlightMode = YES;

// app name, version
NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
NSString *aboutString = [NSString stringWithFormat:@"%@ %@", [info objectForKey:@"CFBundleDisplayName"], [info objectForKey:@"CFBundleShortVersionString"]];
self.aboutMenuItem.title = aboutString;

}

- (void) applicationWillFinishLaunching:(NSNotification *)notification {

self.timers = [[NSMutableArray alloc] initWithCapacity:6];
self.timersQueue = dispatch_queue_create("sunghyuk.d3key.timerQueue", DISPATCH_QUEUE_CONCURRENT);

Expand Down Expand Up @@ -90,13 +97,21 @@ - (IBAction)statusPreferences:(id)sender {
- (void) addTimer:(NSString *) keyCodeKey andWith:(NSString *) delayKey {
NSUInteger delay = [[self.keyConfig valueForKey:delayKey] unsignedIntegerValue];
NSUInteger keyCode = [[self.keyConfig valueForKey:keyCodeKey] unsignedIntegerValue];
BOOL mouseLeftKey = [@"mouseLeftKey" isEqualToString:keyCodeKey] ? YES : NO;
BOOL mouseRightKey = [@"mouseRightKey" isEqualToString:keyCodeKey] ? YES : NO;
if (delay > 0) {
if (delay < 100) {
delay = 100;
}
NSTimeInterval interval = delay*1.0 / 1000;
NSDictionary *userInfo = @{@"keyCode":[NSNumber numberWithUnsignedInteger:keyCode]};
NSLog(@"timer - keyCode: %@, interval: %f", [NSNumber numberWithUnsignedInteger:keyCode], interval);
NSDictionary *userInfo = @{
@"keyCode":[NSNumber numberWithUnsignedInteger:keyCode],
@"delay":[NSNumber numberWithUnsignedInteger:delay],
@"mouseLeftKey": [NSNumber numberWithBool:mouseLeftKey],
@"mouseRightKey": [NSNumber numberWithBool:mouseRightKey]
};
NSLog(@"add timer - userinfo: %@, interval: %f", userInfo, interval);
[self fireEvent:userInfo];
MSWeakTimer *timer = [MSWeakTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(timerFireMethod:) userInfo:userInfo repeats:YES dispatchQueue:self.timersQueue];
[self.timers addObject:timer];
}
Expand Down Expand Up @@ -140,20 +155,22 @@ - (void) postMouseEvent:(CGMouseButton) button eventType:(CGEventType) type
- (void) rightClick
{
[self postMouseEvent:kCGMouseButtonRight eventType: kCGEventRightMouseDown];
sleep(2);
usleep(10);
[self postMouseEvent:kCGMouseButtonRight eventType: kCGEventRightMouseUp];
}

- (void) leftClick
{
[self postMouseEvent:kCGMouseButtonLeft eventType: kCGEventLeftMouseDown];
sleep(2);
usleep(10);
[self postMouseEvent:kCGMouseButtonLeft eventType: kCGEventLeftMouseUp];
}

- (void)timerFireMethod:(NSTimer *)timer {
NSDictionary *userInfo = timer.userInfo;
- (void) fireEvent:(NSDictionary *) userInfo {
NSUInteger keyCode = [[userInfo objectForKey:@"keyCode"] unsignedIntegerValue];
NSUInteger delay = [[userInfo objectForKey:@"delay"] unsignedIntegerValue];
BOOL mouseLeftKey = [[userInfo objectForKey:@"mouseLeftKey"] boolValue];
BOOL mouseRightKey = [[userInfo objectForKey:@"mouseRightKey"] boolValue];

if ([[NSRunningApplication runningApplicationsWithBundleIdentifier:kDiablo3AppId] count]) {
pid_t pid = [(NSRunningApplication*)[[NSRunningApplication runningApplicationsWithBundleIdentifier:kDiablo3AppId] objectAtIndex:0] processIdentifier];
Expand All @@ -166,11 +183,14 @@ - (void)timerFireMethod:(NSTimer *)timer {
OSStatus err = GetProcessForPID(pid, &psn);
if (err == noErr) {
// mouse event
if (keyCode == kCGMouseButtonRight) {
if (mouseRightKey) {
NSLog(@"fire event: mouseRightKey, %tu", delay);
[self rightClick];
} else if (keyCode == kCGMouseButtonLeft) {
} else if (mouseLeftKey) {
NSLog(@"fire event: mouseLeftKey, %tu", delay);
[self leftClick];
} else {
NSLog(@"fire event: %@, %tu", [[D3KeyConfigService sharedService] stringWithKeycode:keyCode], delay);
//resultcode = SetFrontProcess(&psn);
// see HIToolbox/Events.h for key codes
qKeyDown = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)keyCode, true);
Expand All @@ -188,18 +208,20 @@ - (void)timerFireMethod:(NSTimer *)timer {
}
}

- (void)timerFireMethod:(NSTimer *)timer {
[self fireEvent:timer.userInfo];
}

#pragma mark notification observer

- (void) addNotificationObserver {
[[NSNotificationCenter defaultCenter] addObserverForName:kD3KeyStartStopNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * note) {
NSString *action = [note.userInfo objectForKey:@"action"];
if ([action isEqualToString:@"start"]) {
// start operation
NSLog(@"receive start note");
[self startTimer];
} else if ([action isEqualToString:@"stop"]) {
// stop operation
NSLog(@"receive stop note, stop timer");
[self stopTimer];
}
}];
Expand Down
9 changes: 7 additions & 2 deletions d3key/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9532"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand All @@ -13,6 +14,7 @@
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate">
<connections>
<outlet property="aboutMenuItem" destination="i80-CT-VvT" id="435-UJ-te2"/>
<outlet property="statusMenu" destination="YDB-42-1hf" id="vaN-RA-cwN"/>
</connections>
</customObject>
Expand Down Expand Up @@ -668,6 +670,9 @@
</menu>
<menu id="YDB-42-1hf">
<items>
<menuItem title="About" id="i80-CT-VvT">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="설정" id="KQh-kR-XDh">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
Expand Down
4 changes: 2 additions & 2 deletions d3key/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1</string>
<string>1.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2</string>
<string>3</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
Expand Down
10 changes: 8 additions & 2 deletions d3key/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef const_h
#define const_h

static NSString * const kDiablo3AppId = @"com.blizzard.diablo3";
//static NSString * const kDiablo3AppId = @"com.github.atom";
//static NSString * const kDiablo3AppId = @"com.blizzard.diablo3";
static NSString * const kDiablo3AppId = @"com.github.atom";

static NSString * const kD3KeyConfigUserDefaultsKey = @"d3keyconfig";

Expand All @@ -19,4 +19,10 @@ static NSString * const kD3KeyConfigChangedNotification = @"d3keyconfigchanged";
static NSString * const kD3KeyActivatedNotification = @"d3keyactivated";
static NSString * const kD3KeyDeactivatedNotification = @"d3keydeactivated";

#ifdef DEBUG
# define NSLog(...) NSLog(__VA_ARGS__)
#else
# define NSLog(...)
#endif

#endif /* const_h */

0 comments on commit 76268b4

Please sign in to comment.