keyboard
keyboard copied to clipboard
Can't write _(underscore)
I am struggling with writing underscore using keyboard.write
. It throws below error:
Traceback (most recent call last):
File "temp.py", line 3, in <module>
keyboard.write("Trying to write underscore: _")
File "/home/john/pylab/env_test/lib/python3.8/site-packages/keyboard/__init__.py", line 854, in write
scan_code, modifiers = next(iter(entries))
StopIteration
Script Code:
# File: temp.py
import keyboard
keyboard.write("Trying to write underscore: _")
This same for some special keys like *
, %
, ^
etc.
I'm also having this issue
So if I remember correctly, Python has several special characters that are used for various things. I believe the underscore will return the previously calculated value, so inside the library somewhere it probably has some sort of problem with these kinds of characters. If it is using regular expressions (regex), all of these special characters are used as flags for identifying strings.
I am actually not at a computer right now so I have no way of testing this idea, but try using an escape character (\) in front of underscores or asterisks or etc.
Hi, @gavinkrezel I tried using \
after your response but unfortunately, it didn't work.
# File: temp.py
import keyboard
keyboard.write("Trying to write underscore: \_")
Eh it was worth a shot I guess.
You might also be able to format it as a raw string. I think you do that by adding an r in front of your string.
Ex. r"\no more special charac\ters"
Using raw string isn't doing something as well. :laughing:
I guess we shall wait till it gets fixed. :wink:
I'm having the same issues.
Works on OSX Python3.8.6
I think someone has solved it here: https://github.com/boppreh/keyboard/issues/485#issuecomment-1004688511