mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2025-12-08 04:58:48 +00:00
Add hardware keyboard detection on Android
This commit is contained in:
parent
0d91d68300
commit
9a77539664
26
source/funkin/external/android/KeyboardUtil.hx
vendored
Normal file
26
source/funkin/external/android/KeyboardUtil.hx
vendored
Normal file
|
|
@ -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
|
||||
14
source/funkin/external/android/java/funkin/util/KeyboardUtil.java
vendored
Normal file
14
source/funkin/external/android/java/funkin/util/KeyboardUtil.java
vendored
Normal file
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue