summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2012-12-15 21:09:38 +0000
committerSND\MaddTheSane_cp <SND\MaddTheSane_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2012-12-15 21:09:38 +0000
commitb1388179c07a95c63691cf767be999a8e73dead0 (patch)
tree9074ffffae75b7563960459458d5656692a331b7
parentbe3d963074ee8adf5da0371761e090488b3681d3 (diff)
downloadpcsxr-b1388179c07a95c63691cf767be999a8e73dead0.tar.gz
Add missing file from last commit.
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@81771 e17a0e51-4ae3-4d35-97c3-1a29b211df97
-rw-r--r--macosx/hotkeys.m114
1 files changed, 114 insertions, 0 deletions
diff --git a/macosx/hotkeys.m b/macosx/hotkeys.m
new file mode 100644
index 00000000..46ed02e1
--- /dev/null
+++ b/macosx/hotkeys.m
@@ -0,0 +1,114 @@
+//
+// hotkeys.m
+// Pcsxr
+//
+// Created by Nicolas Pepin-Perreault on 12-12-12.
+//
+//
+
+#import <Cocoa/Cocoa.h>
+#import <AppKit/AppKit.h>
+#import "hotkeys.h"
+#import "EmuThread.h"
+#include "plugins.h"
+#include "ExtendedKeys.h"
+#import "PcsxrController.h"
+
+#define HK_MAX_STATE 10
+static id monitor;
+static int currentState = 0;
+static NSMutableDictionary *hotkeys;
+enum {
+ HK_FAST_FORWARD,
+ HK_SAVE_STATE,
+ HK_LOAD_STATE,
+ HK_NEXT_STATE,
+ HK_PREV_STATE
+};
+
+void nextState() {
+ currentState++;
+ if(currentState == HK_MAX_STATE) {
+ currentState = 0;
+ }
+}
+
+void prevState() {
+ currentState--;
+ if(currentState < 0) {
+ currentState = HK_MAX_STATE-1;
+ }
+}
+
+bool handleHotkey(NSString* keyCode) {
+ if([EmuThread active]) { // Don't catch hotkeys if there is no emulation
+ NSNumber *ident = [hotkeys objectForKey:keyCode];
+
+ if(ident != nil) {
+ switch([ident intValue]) {
+ case HK_FAST_FORWARD:
+ // We ignore FastForward requests if the emulation is paused
+ if(![EmuThread isPaused]) {
+ GPU_keypressed(GPU_FAST_FORWARD);
+ }
+ break;
+ case HK_SAVE_STATE:
+ [PcsxrController saveState:currentState];
+ break;
+ case HK_LOAD_STATE:
+ [PcsxrController loadState:currentState];
+ break;
+ case HK_NEXT_STATE:
+ nextState();
+ GPU_displayText((char*)[[NSString stringWithFormat:@"State Slot: %d", currentState] UTF8String]);
+ break;
+ case HK_PREV_STATE:
+ prevState();
+ GPU_displayText((char*)[[NSString stringWithFormat:@"State Slot: %d", currentState] UTF8String]);
+ break;
+ default:
+ NSLog(@"Invalid hotkey identifier.");
+ }
+
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void setupHotkey(int hk, NSString *label, NSDictionary *binding) {
+ [hotkeys setObject:[NSNumber numberWithInt:hk] forKey:[binding objectForKey:@"keyCode"]];
+}
+
+void setupHotkeys() {
+ if(hotkeys) [hotkeys release];
+ NSDictionary *bindings = [[NSUserDefaults standardUserDefaults] objectForKey:@"HotkeyBindings"];
+ hotkeys = [[NSMutableDictionary alloc] initWithCapacity:[bindings count]];
+
+ setupHotkey(HK_FAST_FORWARD, @"FastForward", [bindings objectForKey:@"FastForward"]);
+ setupHotkey(HK_SAVE_STATE, @"SaveState", [bindings objectForKey:@"SaveState"]);
+ setupHotkey(HK_LOAD_STATE, @"LoadState", [bindings objectForKey:@"LoadState"]);
+ setupHotkey(HK_NEXT_STATE, @"NextState", [bindings objectForKey:@"NextState"]);
+ setupHotkey(HK_PREV_STATE, @"PrevState", [bindings objectForKey:@"PrevState"]);
+
+ currentState = 0;
+}
+
+void attachHotkeys() {
+ NSEvent* (^handler)(NSEvent*) = ^(NSEvent *event) {
+ if(handleHotkey([NSString stringWithFormat:@"%d", [event keyCode]])) {
+ return (NSEvent*)nil; // handled
+ }
+
+ // Not handled
+ return event;
+ };
+ setupHotkeys();
+ monitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSKeyUpMask handler:handler];
+}
+
+void detachHotkeys() {
+ if(hotkeys)[hotkeys release];
+ [NSEvent removeMonitor:monitor];
+}