I have a WkWebView browser in my application, is it possible to send an imitation of pressing the F4 button directly to it directly or in some other way?
In a similar application only on Android, I do this using the dispatchKeyEvent() method, and how can this be done in Swift?
In practice, it should look like this: the user launches the application, makes a long tap on the screen and an imitation of pressing the F4 button is triggered.
It remains for me to do an imitation of pressing the F4 key.
Related
I'm writing an AppKit application that within its window may open up a popup menu to resolve ambiguities when certain hot keys are pressed. My problem is that the popup seems to catch all keyboard events so they no longer end up in my main NSView and therefore the main view never seems the key up event. The user presses alt+tab, clicks something in the menu, and my app things alt and tab are still pressed when the popup is gone. Since it's a popup, there is also no event indicating that the window became deactive or otherwise lost focus because it didn't.
Is there:
a way for the view to still receive at least the key up that opened the popup?
a way to read all currently pressed keys (I only know of NSEvent modifierKeys) so I can restore the correct state when I know the popup closes?
Thanks
Hey looking to assign F1 as a hotkey to run a function. I have a windows 32 project with a Form, however the form will be in the background and not the active window when I press F1.
Is there a way to code a hotkey or shortcut so when I press F1 it will run that function even if the Form1 isn't active?
Have a look at the RegisterHotKey function.
It allows you to define a system-wide hot key. When the hot key is pressed, you will receive a WM_HOTKEY message even if your window is not active.
I have a plain UIPageViewController with a data source, in a tvOS project. The swipes for going to previous/next page work fine, but only until I press the “select” button (UIPressType.Select, pressing down the touch pad on the Siri Remote). From that moment on the swipes don’t work anymore, the page view controller just stays on the current page.
There are no custom gesture recognizers, I don’t override any of the press or touch input methods. What could be wrong?
D-oh, it’s just a simulator glitch. After pressing Return on the keyboard, the arrow keys no longer switch pages, but the Siri Remote gestures work fine.
I'm working on an OSX app with DDHotKeyCenter to control youtube/pandora song playbacks and would like to use the Mac play/pause, rewind, and FF buttons; however, they only seem to be accessible by calling the function key that they are mapped to (e.g., 'play' button maps to F8, so user has to hit "fn"+play/F8 button). Ideally, I'd like the user to just be able to hit play instead of having to do a combo.
Is there any way to hook into the play/rewind/FF buttons without the F8 keys? Creative solutions welcome! I'm coming from iOS background so OSX is a bit new to me..
Thanks!
Whether the hardware buttons require the use of the "fn" key or not is controlled by user preferences. See System Preferences > Keyboard pane > Keyboard tab > Use all F1, F2, etc. keys as standard function keys. If that is checked, then the F8 key produces a key event for, well, the F8 key. In order to access the hardware function (e.g. Play/Pause), the user has to hold down "fn".
If that preference setting is not checked, then the behavior is reversed. The F8 key does Play/Pause by default and the user has to hold down "fn" to get a key event.
By the way, third-party keyboards can't access the hardware functions in the same way that Apple keyboards do. So, don't write an app that depends on them being available.
The hardware functions can't be trapped as hot keys. They are intercepted at a low level by the keyboard driver. I have a vague recollection of some very hacky approach to hijacking them, but it won't work to treat them as hot keys.
So, what you're probably finding is that you're able to set up F8 as a hot key for your app's functions, but, since your preference settings are configured so that the F8 key event is only generated when you press fn+F8, you have to use that combo. Pressing the F8 key by itself is generating a hardware function operation which is not visible as a key event.
I am trying to interface with a cocoa popup menu from an OpenGL button. The actual button needs to be in OpenGL and I cannot stick an actual Cocoa button in its place but when this button is pressed I would like for a Cocoa menu to popup just like the one that comes up when you press the nspopupbutton. It seems that there is no way to get this popup window to come up by itself so I wanted to just insert an invisible button and have it be pressed automatically when the popup menu method is called. Is there a way to programmatically set a button to pressed (this will bring up the menu from the popupbutton) and make the button itself invisible without making the resulting menu invisible?
It seems that there is no way to get this popup window to come up by itself
Sure there is. See + popUpContextMenu:withEvent:forView:
Have you thought about just using a regular NSMenu, rather than trying to finagle the menu from an NSPopupButton?