R
R
Rostislav Ivanov2022-01-29 22:52:38
Python
Rostislav Ivanov, 2022-01-29 22:52:38

Python. Pyautogui.hotkey("Ctrl", "с") doesn't work with Russian keyboard layout?

Hello.

There is a small code

import pyautogui as py
import pyperclip as pyp
import time

time.sleep(4)
py.hotkey("ctrl", "c")
a = pyp.paste()
print(a)


I select text like "12345" and run this code.
With the English keyboard layout everything works fine. The text is copied. Output.
But with the Russian keyboard layout, an empty string is displayed in the terminal.

Moreover, in English layout, if I change the text to "123456" and run the code again, the text "123456" is displayed. Those. there will be no problems.
But again, with the Russian layout, no matter how many times I change the text, an empty string is displayed.
Oh, and more. If before that something was copied, for example the word "Hello", then it will be constantly displayed, no matter how many times I run the program and change the text to be copied. Let me remind you, with the Russian keyboard layout.

Question: how to fix? I need the code to be executed with the Russian keyboard layout.
Of course, there may be a command to change the layout to English, execute the code, and then change it back.
But I would like to solve the problem without changing the layout.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question