i can't seem to find any documentation on how to detect the physical keyboard connection (bluetooth) inside a keyboard extension application. Our keyboard extension is helping children suffering dyslexia how to write. I need to detect if a physical keyboard is attached so i don't show the whole virtual keyboard too. I know it's possible because only one application is doing it perfectly and it's called 'Grammarly'. The only thing i tried so far is overriding the pressesBegan function which is not called in a keyboard extension.
func pressesBegan(_ presses: Set<UIPress>,
with event: UIPressesEvent?)
It must be something custom i guess.
You can detect physical keyboard on iOS 14 GameController SDK by using public API GCKeyboard. You just need to import GameController
let isKeyboardConnected = GCKeyboard.coalesced != nil
Related
i know this is a designed part of the ipad to close the keyboard when the hardware keyboard is connected (which make sense). I understand but since ipadOS 15, the virtual keyboard will hide everytime a key is pressed on the hardware keyboard. This was not the case before, you could open it back and use it. We have a prediction keyboard extension which help childrens suffering dyslexia to write. I can't seem to find any documentation on this but is there a private API or something to prevent a virtual keyboard from closing inside a keyboard extension. I can see 'Grammarly' app doing it so it is possible.
So far i can detect if a hardware keyboard is connected using the GameController SDK :
let isKeyboardConnected = GCKeyboard.coalesced != nil
This is not working too inside a keyboard extension
public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
return false
}
I need to see my virtual keyboard at the same time as typing with the hardware keyboard in order to see the prediction view.
Thanks
Is there a way to disable the keyboard in macos x?
I am looking for a way I can use this functinality in an application. So preferably something that can be done programatically and does not need root previlages?
I want the keyboard to be dsabled everywhere in the os, even if the application is in the background, until I enable it by pushing a butten for example.
I am new to mac os programming so will appreciate more elaborations :)
UPDATE: I am trying to use this: CGEventTapCreate but cannot get it to work. Anyone nows how to make it work in swift 3?
You can override the keyDown and keyUp events and leave the function without calling its super class
override func keyDown(with event: NSEvent) {
//super.keyDown(event)
}
override func keyUp(with event: NSEvent) {
//super.keyUp(event)
}
The above code works for NSTextView
For NSTextField, you should manually delete the letter entered. As for NSTextfield's keyDown event will not be called when overrided.
override func keyUp(with event: NSEvent) {
self.stringValue = ""
}
I used these techniques, but not really sure if this is right way to do... But it works :P
I am developing a Mac app using Swift 4 which only runs as an Agent (it only has a menu in the tray). I'm completely new to Swift.
I want it to respond to keyboard shortcuts, but the basic shortcuts (see picture) only work when the app has focus (in my case, when the menu is being clicked).
So what I need is for my app to respond to system-wide keyboard shortcuts.
I've tried:
HotKey but it doesn't seem to be compatible with Swift 4, or perhaps I can't use Swift Package Manager
this answer but again Swift 4 raises several errors that I couldn't solve
Has anyone done it?
So I ended up getting it to work with HotKey:
by using Carthage as a package manager instead of SPM
and by not using HotKey's example code from their README, which for some reason didn't work for me, but the one in their example app.
It works great!
I made a Swift package that makes this very easy:
import KeyboardShortcuts
extension KeyboardShortcuts.Name {
static let startFiveRounds = Self("startFiveRounds", default: .init(.t, modifiers: [.command, .option]))
}
#main
final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
KeyboardShortcuts.onKeyUp(for: .startFiveRounds) {
// …
}
}
}
Even though you already solved your problem, I think this could be useful for other people having the same problem.
I would also recommend letting the user pick their own keyboard shortcut instead of hardcoding it. My package comes with a control where the user can set their preferred shortcut.
Using Xcode 7.3, writing Swift program; searched for this topic but could not find an answer. Apologies, in advance. Last program language was COBOL.
Application background:
It is a single view application, User keys in data and at some point the User 'wins' - at that point, two buttons are available: 'Quit?' and 'Play Again?'
For the 'Quit?' button I have:
// MARK: C.This IBAction used to quit the game
#IBAction func quitIt(sender: AnyObject)
{
exit(0)
}
Hopefully, the above is the most efficient way.
What I need help on is the 'Play Again?' button:
// TODO: B. This IBAction used to play another game
#IBAction func Playagain(sender: AnyObject)
{
}
What code do I put in?
Move the startup code for your game to it's own func(tion).
Call that function both from [wherever you moved it from] and also in PlayAgain().
I hope this is for OS X rather than iOS - Apple will probably reject your iOS app if it exits. They consider that "crashing".
https://developer.apple.com/library/ios/qa/qa1561/_index.html
I'm really bangin' my head because I can't find the way to show the soft keyboard when there's a bluetooth input device connected to the iPad. I made some search on the web and this is the result:
a question on stackoverflow with a very short answer How can I detect if an external keyboard is present on an iPad?
an application developed by erica sadun for the cydia env http://www.tuaw.com/2010/06/02/hacksugar-bringing-back-the-on-screen-keyboard/
Erica said that the trick is to answer to the system that "There's no hardware keyboard attached".
I tried to write a category for UIKeyboardImpl and I overrided:
- (BOOL)isInHardwareKeyboardMode {
DEBUG(#"is called");
return NO;
}
But until now I haven't obtained anything. The overrided method is called but there's no soft keyboard.
Erica also said the application works by dynamic linking but I don't know how can I accomplish it. I don't need to be in the AppStore because this is a private application so I don't bother about rejection.
Thanks in advance
Ok. Finally got it. Many thanks to David, Matthias and Enrico. Here are the steps:
import the private framework GraphicsServices
call GSEventSetHardwareKeyboardAttached(NO) inside the viewDidLoad
add a button that toggles the keyboard by calling
static void toggleKeyboard(UIKeyboardImpl * keyImpl){
if (UIKeyboardAutomaticIsOnScreen()) {
UIKeyboardOrderOutAutomatic();
} else {
UIKeyboardOrderInAutomatic();
}
I've found this function on http://code.google.com/p/btstack/wiki/iPhoneKeyboardHiding
Now I can take input from the soft keyboard and from the bluetooth device at the same time.
To get around it using the apple keyboard you hit the eject key. Perhaps you can implement an action that sends the eject keycode? I think iSSH has a feature where you can tap the onscreen keyboard icon to bring it up even when a bluetooth keyboard is connected.