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.