nsevent

how to handle key events in iphone

与世无争的帅哥 提交于 2019-11-30 15:22:36
Hi I am working on an iphone application and want to handle keyboard events in iphone. In Mac, there is a class NSEvent which handles both keyboard and mouse events, and in ios (iphone/ipad) the counterpart of NSEvent is UIEvent which handles only touch events. I know ios API does not provide this functionality, but how can i handle key events in iphone??? Any good tutorial or sth, to get started... You cant directly code for keyboad;s key and there is no mouse in case of device. you can make your logics for different kind of charectersets or you can make your logics in textField delgate

Mac Cocoa: How to differentiate if a NSScrollWheel event is from a mouse or trackpad?

点点圈 提交于 2019-11-30 13:49:25
In my application, I want the scrolling to happen, only with scroll wheel action from a mouse and not from the two finger gesture on a trackpad. Basically, I am trying to determine if the scrollWheelEvent is generated from the mouse or trackpad, inside - (void)scrollWheel:(NSEvent *)theEvent method. From what I know so far, it seems like there is no straightforward way to accomplish this. I tried a work around of setting a boolean variable to true and false inside -(void)beginGestureWithEvent:(NSEvent *)event; and -(void)endGestureWithEvent:(NSEvent *)event; But this is not a solution because

Check modifierFlags of NSEvent if a certain modifier was pressed but no other

好久不见. 提交于 2019-11-30 05:11:52
I just experimented with the addLocalMonitorForEventsMatchingMask:handler: method in NSEvent and came across the following question: How do I find out if only certain modifiers were pressed? A short example to set this question into context: I wanted to listen for the shortcut "⌘+W". Therefore I wrote the following code: [NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask handler:^(NSEvent *theEvent) { if ([theEvent modifierFlags] & NSCommandKeyMask && [theEvent keyCode] == 13) { [self.window performClose:self]; } return theEvent; }]; This works well, however the shortcut will be

how to handle key events in iphone

房东的猫 提交于 2019-11-29 22:12:10
问题 Hi I am working on an iphone application and want to handle keyboard events in iphone. In Mac, there is a class NSEvent which handles both keyboard and mouse events, and in ios (iphone/ipad) the counterpart of NSEvent is UIEvent which handles only touch events. I know ios API does not provide this functionality, but how can i handle key events in iphone??? Any good tutorial or sth, to get started... 回答1: You cant directly code for keyboad;s key and there is no mouse in case of device. you can

How to capture Unicode from key events without an NSTextView

夙愿已清 提交于 2019-11-29 22:00:22
问题 I'd like to capture key events from any window in the application and interpret them as Unicode. For example, if the user types Option-e-e (on a default-configured US English keyboard), I would like to recognize that as "é". I tried capturing keypress events and calling -[NSEvent characters] . However, as it says in the documentation, "This method returns an empty string for dead keys, such as Option-e." If I type Option-e-e , then it gives me nothing for the Option-e and plain "e" for the

Cocoa - NSEvent Respond to the SHIFT key?

懵懂的女人 提交于 2019-11-29 11:55:51
I was wondering if NSEvent responds to the "Shift" key on the keyboard. I am logging the keyCodes when debugging my app and I don't get a keyCode value for the shift key. Thanks, Kevin EDIT: This is the code I am using from a user response. -(void)keyDown:(NSEvent*)event { if ([event modifierFlags] == NSShiftKeyMask) { NSLog(@"Shift key pressed"); } } The Shift key is still not being recognized... Take a look at the flagsChanged: method of NSResponder . Something like this: - (void) flagsChanged:(NSEvent *) event { if ([event modifierFlags] & NSShiftKeyMask) { //Do something } } Your code

Detect any key press, including modifier keys, on OS X

泪湿孤枕 提交于 2019-11-27 08:22:54
问题 I need to detect all the keys that the user presses. Using -keyDown: I can get most key presses (alphanumeric, function keys, arrows, space bar, escape, return), but I cannot get any modifier key when it's pressed alone. How do I detect absolutely any keystroke, including modifier keys? 回答1: Try it: [NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask|NSFlagsChangedMask handler:^NSEvent *(NSEvent *incomingEvent) { if (incomingEvent.type == NSFlagsChanged && (incomingEvent.modifierFlags

Modify NSEvent to send a different key than the one that was pressed

半城伤御伤魂 提交于 2019-11-26 17:35:05
I'm trying to create an OS X keyboard hook for assistive technology purposes (i.e. don't worry, not a keylogger). When a user presses a key, I want to prevent the real keypress and send a fake keypress (character of my choosing) instead. I have the following code: - (void) hookTheKeyboard { CGEventMask keyboardMask = CGEventMaskBit(kCGEventKeyDown); id eventHandler = [NSEvent addGlobalMonitorForEventsMatchingMask:keyboardMask handler:^(NSEvent *keyboardEvent) { NSLog(@"keyDown: %c", [[keyboardEvent characters] characterAtIndex:0]); //Want to: Stop the keyboard input //Want to: Send another key

Modify NSEvent to send a different key than the one that was pressed

梦想与她 提交于 2019-11-26 06:06:48
问题 I\'m trying to create an OS X keyboard hook for assistive technology purposes (i.e. don\'t worry, not a keylogger). When a user presses a key, I want to prevent the real keypress and send a fake keypress (character of my choosing) instead. I have the following code: - (void) hookTheKeyboard { CGEventMask keyboardMask = CGEventMaskBit(kCGEventKeyDown); id eventHandler = [NSEvent addGlobalMonitorForEventsMatchingMask:keyboardMask handler:^(NSEvent *keyboardEvent) { NSLog(@\"keyDown: %c\", [