Add support for keyboard input that is not normalized to US English layout
This is used by the soft keyboards on Android and iOS
This commit is contained in:
@@ -436,7 +436,7 @@ namespace platf {
|
||||
void
|
||||
hscroll(input_t &input, int distance);
|
||||
void
|
||||
keyboard(input_t &input, uint16_t modcode, bool release);
|
||||
keyboard(input_t &input, uint16_t modcode, bool release, uint8_t flags);
|
||||
void
|
||||
gamepad(input_t &input, int nr, const gamepad_state_t &gamepad_state);
|
||||
void
|
||||
|
||||
@@ -1337,14 +1337,15 @@ namespace platf {
|
||||
* @param input The input_t instance to use.
|
||||
* @param modcode The moonlight key code.
|
||||
* @param release Whether the event was a press (false) or a release (true)
|
||||
* @param flags SS_KBE_FLAG_* values
|
||||
*
|
||||
* EXAMPLES:
|
||||
* ```cpp
|
||||
* x_keyboard(input, 0x5A, false); // Press Z
|
||||
* x_keyboard(input, 0x5A, false, 0); // Press Z
|
||||
* ```
|
||||
*/
|
||||
static void
|
||||
x_keyboard(input_t &input, uint16_t modcode, bool release) {
|
||||
x_keyboard(input_t &input, uint16_t modcode, bool release, uint8_t flags) {
|
||||
#ifdef SUNSHINE_BUILD_X11
|
||||
auto keycode = keysym(modcode);
|
||||
if (keycode.keysym == UNKNOWN) {
|
||||
@@ -1371,17 +1372,18 @@ namespace platf {
|
||||
* @param input The input_t instance to use.
|
||||
* @param modcode The moonlight key code.
|
||||
* @param release Whether the event was a press (false) or a release (true)
|
||||
* @param flags SS_KBE_FLAG_* values
|
||||
*
|
||||
* EXAMPLES:
|
||||
* ```cpp
|
||||
* keyboard(input, 0x5A, false); // Press Z
|
||||
* keyboard(input, 0x5A, false, 0); // Press Z
|
||||
* ```
|
||||
*/
|
||||
void
|
||||
keyboard(input_t &input, uint16_t modcode, bool release) {
|
||||
keyboard(input_t &input, uint16_t modcode, bool release, uint8_t flags) {
|
||||
auto keyboard = ((input_raw_t *) input.get())->keyboard_input.get();
|
||||
if (!keyboard) {
|
||||
x_keyboard(input, modcode, release);
|
||||
x_keyboard(input, modcode, release, flags);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -230,7 +230,7 @@ const KeyCodeMap kKeyCodesMap[] = {
|
||||
}
|
||||
|
||||
void
|
||||
keyboard(input_t &input, uint16_t modcode, bool release) {
|
||||
keyboard(input_t &input, uint16_t modcode, bool release, uint8_t flags) {
|
||||
auto key = keysym(modcode);
|
||||
|
||||
BOOST_LOG(debug) << "got keycode: 0x"sv << std::hex << modcode << ", translated to: 0x" << std::hex << key << ", release:" << release;
|
||||
|
||||
@@ -338,15 +338,16 @@ namespace platf {
|
||||
}
|
||||
|
||||
void
|
||||
keyboard(input_t &input, uint16_t modcode, bool release) {
|
||||
keyboard(input_t &input, uint16_t modcode, bool release, uint8_t flags) {
|
||||
auto raw = (input_raw_t *) input.get();
|
||||
|
||||
INPUT i {};
|
||||
i.type = INPUT_KEYBOARD;
|
||||
auto &ki = i.ki;
|
||||
|
||||
// For some reason, MapVirtualKey(VK_LWIN, MAPVK_VK_TO_VSC) doesn't seem to work :/
|
||||
if (modcode != VK_LWIN && modcode != VK_RWIN && modcode != VK_PAUSE && raw->keyboard_layout != NULL) {
|
||||
// If the client did not normalize this VK code to a US English layout, we can't accurately convert it to a scancode.
|
||||
if (!(flags & SS_KBE_FLAG_NON_NORMALIZED) && modcode != VK_LWIN && modcode != VK_RWIN && modcode != VK_PAUSE && raw->keyboard_layout != NULL) {
|
||||
// For some reason, MapVirtualKey(VK_LWIN, MAPVK_VK_TO_VSC) doesn't seem to work :/
|
||||
ki.wScan = MapVirtualKeyEx(modcode, MAPVK_VK_TO_VSC, raw->keyboard_layout);
|
||||
}
|
||||
|
||||
@@ -355,7 +356,7 @@ namespace platf {
|
||||
ki.dwFlags = KEYEVENTF_SCANCODE;
|
||||
}
|
||||
else {
|
||||
// If there is no scancode mapping, send it as a regular VK event.
|
||||
// If there is no scancode mapping or it's non-normalized, send it as a regular VK event.
|
||||
ki.wVk = modcode;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user