1

I am using Keyboard global hook library in Python (https://github.com/boppreh/keyboard) to simulate key pressing in other applications (during text entry I am replacing accents on words).

Everything works fine for simple combinations such as 'ctrl+c' or 'ctrl+v', but I also need to simulate a bit more complex combinations, most importantly 'ctrl+shift+left', which is essentially a 'ctrl+shift and left arrow key' on the keyboard (to highlight the last word in text).

Does anyone know how to do this in Python using above library? Or even without the library?

Currently I do something like this, to first press ctrl+shift, keep it pressed, then pass left arrow key and then release ctrl+shift:

keyboard.press_and_release('ctrl+shift', True, False)
keyboard.press_and_release('left', True, True)
keyboard.press_and_release('ctrl+shift', False, True)

But for some reason this doesn't work, it doesn't highlight the last word in text. Same as this, which also doesn't work:

keyboard.press('ctrl+shift+left')

Nor this:

keyboard.send('ctrl+shift+left', True, False)
keyboard.send('ctrl+shift+left', False, True)

Any ideas how to get this working?

1 Answer 1

1

I found a library that does this. The following code is what I think you need. You do need to install pynput.keyboard though. In the Youtube Video Down Below you Can Find How To Do That

from pynput.keyboard import Key, Controller
import time
keyboard = Controller()
keyboard.press (Key.ctrl )
keyboard.press (Key.left )
keyboard.press (Key.shift )
time.sleep (0.5)
keyboard.release (Key.ctrl )
keyboard.release (Key.left )
keyboard.release (Key.shift )

A youtube video explaining this is here: https://www.youtube.com/watch?v=DTnz8wA6wpw

For a list of more keys go here: https://pythonhosted.org/pynput/keyboard.html#pynput.keyboard.Key`

Sorry for Late Response, Good Luck

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.