1. Brandon Walkin
  2. BWToolkit

Commits

Brandon Walkin  committed 19a97e7

Added NSEvent category

  • Participants
  • Parent commits 8edb347
  • Branches default

Comments (0)

Files changed (2)

File NSEvent+BWAdditions.h

View file
  • Ignore whitespace
+//
+//  NSEvent+BWAdditions.h
+//  BWToolkit
+//
+//  Created by Brandon Walkin (www.brandonwalkin.com)
+//  All code is provided under the New BSD license.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@interface NSEvent (BWAdditions)
+
++ (BOOL)shiftKeyIsDown;
++ (BOOL)commandKeyIsDown;
++ (BOOL)optionKeyIsDown;
++ (BOOL)controlKeyIsDown;
++ (BOOL)capsLockKeyIsDown;
+
+@end

File NSEvent+BWAdditions.m

View file
  • Ignore whitespace
+//
+//  NSEvent+BWAdditions.m
+//  BWToolkit
+//
+//  Created by Brandon Walkin (www.brandonwalkin.com)
+//  All code is provided under the New BSD license.
+//
+
+#import "NSEvent+BWAdditions.h"
+
+@implementation NSEvent (BWAdditions)
+
++ (BOOL)shiftKeyIsDown
+{
+	if ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask)
+		return YES;
+	
+	return NO;
+}
+
++ (BOOL)commandKeyIsDown
+{
+	if ([[NSApp currentEvent] modifierFlags] & NSCommandKeyMask)
+		return YES;
+	
+	return NO;
+}
+
++ (BOOL)optionKeyIsDown
+{
+	if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
+		return YES;
+	
+	return NO;
+}
+
++ (BOOL)controlKeyIsDown
+{
+	if ([[NSApp currentEvent] modifierFlags] & NSControlKeyMask)
+		return YES;
+	
+	return NO;
+}
+
++ (BOOL)capsLockKeyIsDown
+{
+	if ([[NSApp currentEvent] modifierFlags] & NSAlphaShiftKeyMask)
+		return YES;
+	
+	return NO;
+}
+
+@end