Add hardware keyboard detection on Android
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
package funkin.external.android;
|
||||
|
||||
#if android
|
||||
import lime.system.JNI;
|
||||
|
||||
/**
|
||||
* Utility class for keyboard detection.
|
||||
*/
|
||||
class KeyboardUtil
|
||||
{
|
||||
/**
|
||||
* Returns `true` if a keyboard is currently connected to the device.
|
||||
*/
|
||||
public static var keyboardConnected(get, never):Bool;
|
||||
|
||||
@:noCompletion
|
||||
static function get_keyboardConnected():Bool
|
||||
{
|
||||
final method:Null<Dynamic> = JNIUtil.createStaticMethod('funkin/util/KeyboardUtil', 'isKeyboardConnected', '()Z');
|
||||
|
||||
if (method == null) return false;
|
||||
|
||||
return inline JNI.callStatic(method, []);
|
||||
}
|
||||
}
|
||||
#end
|
||||
@@ -0,0 +1,14 @@
|
||||
package funkin.util;
|
||||
|
||||
import org.haxe.extension.Extension;
|
||||
|
||||
public class KeyboardUtil
|
||||
{
|
||||
public static boolean isKeyboardConnected()
|
||||
{
|
||||
if (Extension.mainContext == null) return false;
|
||||
|
||||
// KEYBOARD_UNDEFINED = 0, KEYBOARD_NOKEYS = 1
|
||||
return Extension.mainContext.getResources().getConfiguration().keyboard > 1;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,9 @@ import funkin.mobile.ui.FunkinHitbox;
|
||||
import funkin.play.notes.NoteDirection;
|
||||
import openfl.events.KeyboardEvent;
|
||||
import openfl.events.TouchEvent;
|
||||
#if android
|
||||
import funkin.external.android.KeyboardUtil;
|
||||
#end
|
||||
|
||||
/**
|
||||
* Handles setting up and managing input controls for the game.
|
||||
@@ -125,7 +128,7 @@ class ControlsHandler
|
||||
@:noCompletion
|
||||
private static function get_hasExternalInputDevice():Bool
|
||||
{
|
||||
return FlxG.gamepads.numActiveGamepads > 0 #if android || extension.androidtools.Tools.isChromebook() #end;
|
||||
return FlxG.gamepads.numActiveGamepads > 0 #if android || KeyboardUtil.keyboardConnected || extension.androidtools.Tools.isChromebook() #end;
|
||||
}
|
||||
|
||||
@:noCompletion
|
||||
|
||||
Reference in New Issue
Block a user