Why I fail to use Python to control mouse and keyboard in THAT window?

I wanna use Python to control mouse and keyboard in our HIS (Hospital information system). The program works alright when other windows are on top, such as notebook, Chrome, Office.

import pyautogui direction = 1 while True: pyautogui.move(200 * direction, 0, 0.5) direction = direction * -1

When I run this code, I can see the cursor shuttling. But it stops as I switch to the HIS window by pressing Alt+Tab. It starts shuttling again when I switch to other windows.
Here’s another case:

import pyautogui pyautogui.hotkey('alt', 'esc') while True: for x in range(0, 10): pyautogui.press(str(x))

When I run this code, I can see that another window(Notebook) is switched on top and numbers are being typed.
But it stops as I switch to the HIS window by pressing Alt+Tab or clicking mouse. The insertion point is just blinking, but it doesn’t type any number. It starts typing again when I switch back to Notebook.

Could someone tell me why and how to fix it, please?
Thank you!

Hello, welcome to the forums!

I also testing and your code works perfectly on my system, so just to clarify your code works fine on other windows but stops when specifically on the HIS window?

Now take this with a grain of salt since I have zero actual knowledge of the system of course, but if I had to hazard a guess it might be a security feature of the HIS to prevent automation given the strong privacy concerns around confidential medial information, and that would seem like a sensible security policy. If that is the case, then there wouldn’t really be a way to bypass it unfortunately.

1 Like

Reply to notlyall:
Yes. My code works fine on other windows except on the HIS window. I also wrote code on Java to control mouse and keyboard. It also failed on the HIS window.
By the way, when I turned on Mouse Keys on Windows 10, I was able to control mouse with keyboard on the HIS window.
I just want to improve my work efficiency with that program I made. Now I am so frustrated. :face_exhaling:
But I will not give up. :wink:
Thanks for your comment.