Selaa lähdekoodia

Add getKeyboardLayout, onKeyboardLayoutChange (hl only) (#1288)

Yuxiao Mao 2 kuukautta sitten
vanhempi
commit
a42d8a6145
4 muutettua tiedostoa jossa 63 lisäystä ja 0 poistoa
  1. 31 0
      hxd/System.hl.hx
  2. 14 0
      hxd/System.hx
  3. 14 0
      hxd/System.js.hx
  4. 4 0
      hxd/Window.hl.hx

+ 31 - 0
hxd/System.hl.hx

@@ -21,6 +21,14 @@ enum SystemValue {
 	IsMobile;
 }
 
+enum KeyboardLayout {
+	QWERTY;
+	AZERTY;
+	QWERTZ;
+	QZERTY;
+	Unknown;
+}
+
 //@:coreApi
 class System {
 
@@ -418,6 +426,29 @@ class System {
 		return _loc;
 	}
 
+	/**
+		The value isn't reliable on SDL when used without a window.
+	**/
+	public static function getKeyboardLayout() : KeyboardLayout {
+		var layoutStr = null;
+		#if hlsdl
+		layoutStr = sdl.Sdl.detectKeyboardLayout();
+		#elseif (hldx >= version("1.16.0"))
+		layoutStr = dx.Window.detectKeyboardLayout();
+		#elseif (hldx && !dx12)
+		layoutStr = dx.Driver.detectKeyboardLayout();
+		#end
+		return switch(layoutStr) {
+			case "qwerty": QWERTY;
+			case "azerty": AZERTY;
+			case "qwertz": QWERTZ;
+			case "qzerty": QZERTY;
+			case null, _: Unknown;
+		};
+	}
+
+	public static dynamic function onKeyboardLayoutChange() : Void {}
+
 	// getters
 
 	#if usesys

+ 14 - 0
hxd/System.hx

@@ -15,6 +15,14 @@ enum SystemValue {
 	IsMobile;
 }
 
+enum KeyboardLayout {
+	QWERTY;
+	AZERTY;
+	QWERTZ;
+	QZERTY;
+	Unknown;
+}
+
 class System {
 
 	public static var width(get,never) : Int;
@@ -89,6 +97,12 @@ class System {
 		return "en_EN";
 	}
 
+	public static function getKeyboardLayout() : KeyboardLayout {
+		return Unknown;
+	}
+
+	public static dynamic function onKeyboardLayoutChange() : Void {}
+
 	// getters
 
 	static function get_width() : Int return 0;

+ 14 - 0
hxd/System.js.hx

@@ -15,6 +15,14 @@ enum SystemValue {
 	IsMobile;
 }
 
+enum KeyboardLayout {
+	QWERTY;
+	AZERTY;
+	QWERTZ;
+	QZERTY;
+	Unknown;
+}
+
 class System {
 
 	public static var width(get,never) : Int;
@@ -159,6 +167,12 @@ class System {
 		return js.Browser.navigator.language + "_" + js.Browser.navigator.language.toUpperCase();
 	}
 
+	public static function getKeyboardLayout() : KeyboardLayout {
+		return Unknown;
+	}
+
+	public static dynamic function onKeyboardLayoutChange() : Void {}
+
 	// getters
 
 	static function get_width() : Int return Math.round(js.Browser.document.body.clientWidth * js.Browser.window.devicePixelRatio);

+ 4 - 0
hxd/Window.hl.hx

@@ -553,6 +553,10 @@ class Window {
 			for ( dt in dropTargets ) dt(event);
 			dropFiles = null;
 		#end
+		#if (hlsdl >= version("1.16.0") || hldx >= version("1.16.0"))
+		case KeyMapChanged:
+			hxd.System.onKeyboardLayoutChange();
+		#end
 		#if !hlsdl // hlsdl post both Close+Quit
 		case Quit:
 			return onCloseEvent();