Is it possible to change what each key does? I have a client application and the way it needs to work is that each key press is a command to send over the network. I do not need my keyboard to produce letters (the server will do this) when pressed but commands to the server. Currently I have this working by making a custom view that looks like a keyboard however it would look better if it was the ios default keyboard.
Of course I dont expect the code but I need a starting point. My current google searching hasnt gone to good. Maybe a link to an example or some documentation on how to do it.
notes: you will see the first answer below makes a good suggestion but it brings up another point. my keyboard needs to mask the keyboard of the server, so no .com button or any other out of the ordinary keys, so I would also need to edit the layout I guess.
Create a text field with a custom delegate, hide it and set it as the first responder. Then you can hook into the delegate methods to work out what was pressed.
Related
I'm currently working on an OSX menubar app that uses a custom status item view and a NSPopover to display content.
I'm trying to get it to dismiss at times that would make sense like when spaces are changed, since the popover doesn't move spaces like a window does, or when mission controller is activated.
Currently, when in mission control, the NSPopover stays on top as shown in this screenshot.
Currently I'm using NSEvent addGlobalMonitorForEventsMatchingMask: with some mouse event masks and that works alright but doesn't cover all needed events.
So, is there a way to detect when major OS events happen like opening mission control, changing spaces etc?
Any help would be greatly appreciated.
You can get notified of space changes by registering for NSWorkspace's NSWorkspaceActiveSpaceDidChangeNotification. There isn't a notification as such for Mission Control, but you might investigate whether NSWorkspaceDidActivateApplicationNotification or other notifications can be used to determine what you need.
HTH
Apologies in advance if this is answered but I genuinely couldn't find it. I'm trying to bring up the keyboard type on iPad which appears when pressing the "#+=" button. I've tried going through all the types on the docs and I'm sure that this wasn't successful. Am I missing something or does the user have to click this button every time?
Edit: this question was closed as "off-topic" because it didn't include code or ideas or what I've tried already... Therefore for a bit of extra detail, I used EVERY keyboard type that is available on the docs e.g.
theTextField.keyboardType = UIKeyboardTypeNumberPad;
This did not yield the results that I require, which is the keyboard plane that appears when you press the #+= button because I wanted users to go straight to that one.
Unfortunately, this is impossible. It's not a keyboard type you want, it's a keyboard plane. There is no public API to switch or in any way access the keyboard planes.
One solution could be to create your own keyboard with the symbols you want. Another solution would be to open the keyboard and then generate a touch event that will switch the keyboard plane. However, this would be complicated, non-portable and a bit dangerous.
You have no ability to affect the built-in keyboards.
You can however create your own custom input view which you would set on the inputView of your text editing view before you make it first responder. Then iOS will show this view instead.
Have a look at this project of mine which implemented a "Morse keyboard" (April Fool's joke), but demonstrates how to achieve a custom keyboard that still interacts with a text field as you'd expect. http://www.cocoanetics.com/2012/04/dtmorsekeyboard-tutorial/
In my Cocoa/Objective-C application I have a utility panel floating "always on top" to be accessible even when my application is not active. I am trying to disable the "switching to my application when a user clicks on that panel".
The behaviour I would like to achieve is similar to OSX's Keyboard Viewer, (which is also a never activating panel), so that some other application remained active after clicking on my app's panel. i.e. Safari stays active when typing an address using Keyboard Viewer. Even third-party onscreen keyboards have this functionality (for example the one from CORALLO Software), which means this behavior is not reserved system-only.
I was messing around with NSApplicationActivationPolicy, but without positive results. In which direction should I go?
You should take a look at the canBecomeKeyWindow and canBecomeMainWindow methods on NSWindow. It sounds like you want your window to maintain key status while not being able to be the main window. Here are some resources to help you:
Window Programming Guide - Explains the difference between main and key windows
NSWindow class reference - Jump to the sections on canBecomeKeyWindow and canBecomeMainWindow
I've found a bug with WebView that is easy to recreate but hard to solve and am looking for suggestions and preferably answers.
The bug is when you use Apple's built in dictionary "look up" command by any means, contextual menu, multi touch gesture (3 finger double tap), or the standard global hot key "cmd ctrl d". After invoking the dictionary look up command, a popover will appear with the definition of the word you highlighted. However, text on the page sometimes gets blurred and forms/fields no longer respond properly to input events like mouseDown.
Like I said earlier, it is pretty easy to duplicate. I've uploaded a sample project to GitHub.
https://github.com/ChimpStudios/WebView-DictionaryBug
Safari doesn't have this bug, so somehow Apple fixed it, but it still exists in the WebView object.
Calling -[WebPreferences setPreferencesIdentifier:] so that your WebView gets its own WebPreferences copy appears to be an effective workaround.
I'm creating an application that emulates MacBook's multi-touch Trackpad. As you may know, on MacBook's trackpad
if you swipe 4 fingers up, it triggers the Show Desktop.
if you swipe 4 fingers down, it shows the Exposé.
However, if the Show Desktop is being activated and you swipe 4 fingers down, it will come back to the normal mode. The same goes with the Exposé: if the Exposé is being activated and you swipe 4 fingers up, it will also come back to the normal mode.
Here is the problem: I use the keyboard shortcut F3 to show the Exposé and F11 to show the Show Desktop. The problem is, when the Show Desktop is being activated, if I press F3, it will go straight to the Exposé. And when the Exposé is being activated, if I press F11 it will go straight to the Show Desktop. But I want it to behave like Trackpad, which I guess its code may look like this
- FourFingersDidSwipeUp {
if (isExposeBeingActivated() || isShowDesktopBeingActivated()) {
pressKey("Esc");
} else {
pressKey("F11");
}
}
But I don't know how to implement the "isExposeBeingActivated()" and "isShowDesktopBeingActivated()" methods. I've tried creating a window and check whether its size has changed (on assumption that if the Expose is being activated, its size should be smaller), but the system always returns the same size. I tried monitoring the background processes during the Expose, but nothing happened. Does anyknow have any suggestions on this?
(I'm sorry if my English sounds weird.)
As far as I know, there's no public interface to any Exposé related functionality beyond the ability to specify the "collection behavior" of your own application's windows.
came here after reading your email. I understand the problem. After a bit of googling I found out what you already know, that there's really no official API or documentation for Exposé. A very ugly solution I've thought of could be having Exposé trigger a timer equal to the total time it takes to show all windows fully (guessing this is constant). If a swipe up would be done within that timer, it would mean that Exposé would still be active (isExposeBeingActivated()), so you would trigger a cancel instead of a Show Desktop. This wouldn't cover the use of the "slow motion" Exposé (via SHIFT key). Maybe you can detect if it's a normal or "slow motion" Exposé call?
Really sorry if this doesn't make sense at all within your application's scope, guess I'm just really saying the first solution I thought of.
Cheers.
Pedro.