Reputation: 151
Today I was writing a simple script using pyautogui and at some point I had to write the <
sign, but pyautogui for some reason writes >
instead of <
. I tried using write
, typewrite
and press
functions. It does not flip curly, normal and squared brackets, and the >
sign.
Does anyone know why is this happening?
Upvotes: 1
Views: 485
Reputation: 1180
This usually happens due to the use of non-qwerty keyboards. When you use write
(or press
), pyautogui doesn't actually write that character, instead it looks for the associated key on your keyboard and presses it. As a part of this, it decides whether or not it needs to hold Shift
while pressing this key to get the correct character written (for example to differentiate between a
and A
). As you can see in the code here, the implementation of that is very minimalistic, and it even has a note saying that it will be different for non-qwerty keyboards. As you can see, both <
and >
return True
when passed to that function.
So what I assume is that on your keyboard <
and >
are on the same key and you select between them by holding or not holding Shift
. Pyuatogui will, however, press both with Shift
(because the function return True
for both), thus always writing the one that you get when you hold Shift
and press the key.
You can either solve this by using a standart qwerty keyboard or by copying the <
into your clipboard and then pasting it using pyautogui.hotkey
. To copy a string to the clipboard see this question, or pyperclip.
Upvotes: 3