#Unlocking Keyboard Interaction in Tauri: Seeking Solutions Beyond Window Focus

3 messages · Page 1 of 1 (latest)

thorn pasture
#

I'm working on a project where I need to integrate keyboard input into a Tauri application. I'm primarily using Python for this integration, but I've encountered difficulties in getting the Tauri app to respond to the keyboard events.(I have a svelte:window> listener for keypresses)

The primary challenge is that I'd like the Tauri application to respond to keyboard input without requiring its window to be in focus. I've explored various methods to achieve this, but I'm open to suggestions or insights into why my Tauri app may not be registering the keyboard events as expected.

Here's a simplified example of my Python code:

import win32api
import win32con
import win32gui
import time

hwndMain = win32gui.FindWindow(None, "Johnson_City_TN")

if hwndMain == 0:
    print(f"Window with the title 'Johnson_City_TN' was not found.")

def send_arrow_key(hwnd, key_code):
    win32api.PostMessage(hwnd, win32con.WM_KEYDOWN, key_code, 0)
    time.sleep(0.5)  # Adjust the delay as needed
    win32api.PostMessage(hwnd, win32con.WM_KEYUP, key_code, 0)

time.sleep(2)

# Send the 'L' key
send_arrow_key(hwndMain, ord('L'))

The focus here is to understand why my Tauri application might not be responding to the keyboard events when using this approach. Any advice or insights into how to make this interaction successful would be greatly appreciated.

idle jolt
#

There are a few methods I have tried before.

  1. rdev. It is probably the best solution as it works on Windows, Linux and macOS. But there are a few disadvantages:
  • it creates its own event loop and blocks the thread it runs on
  • there is no built-in function to stop the hook