I am trying to understand the behavior I am seeing from running my script below and how I can get my desired outcome. Basically I'm using keyboard.add_word_listener() to run a function when the string "test" is typed. It should select the tab trigger key plus the "test" text and then copy it, and then replace it with bbbb and then the copied text.
But if you look at the gif, it doesn't highlight the text. The "bbbb" gets inserted to the left of the "test" text. But it should have replaced the "test" text since it sends ctrl+shift+left which should select the previously entered text. The strange thing is the text still gets copied to the clipboard even though it doesn't look like it got selected. And for some reason it gets pasted in a separate line in the beginning. I don't understand how that is possible. It works on macOS but not Windows.
I also tried replacing ctrl+shift+left,ctrl+shift+left
with shift+home
but the result is the same.
The script:
import keyboard
import time
def test():
keyboard.send("ctrl+shift+left,ctrl+shift+left")
time.sleep(1)
keyboard.send("ctrl+c")
time.sleep(1)
keyboard.send("b,b,b,b")
time.sleep(1)
keyboard.send("ctrl+v")
keyboard.add_word_listener("test",test,['tab'],False,1)
keyboard.wait()