Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have two images open in a full-screen mode on my Raspberry Pi (using ristretto image viewer). When certain conditions are met, I need to pass an ALT+TAB keystroke combination to display the other one. I am trying to use Popen.communicate, but I don't know how to pass a key combination like ALT+TAB). Does anyone have any ideas?

What I need is something like below (replacing "ALT+TAB" with a working code):

s = Popen(['ristretto', '-f', 'my.gif' ,'&'],stdin=PIPE)
if my_condition:
    s.communicate("ALT+TAB")

I heard about SendKeys package, but it works only for Windows...

Thanks, Michal

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.7k views
Welcome To Ask or Share your Answers For Others

1 Answer

You probably can't do exactly what your question says - pass keystrokes using Popen. You can send bytes to the stdin of the process you've opened, but it's almost certainly not looking there for them. Keyboard events are different from data coming on stdin.

The pyautogui library library could be useful for this purpose, however. Once it's installed, you could launch your viewer with Popen, as you've done, and then use

pyautogui.hotkey('alt', 'tab')

To send alt+tab to the foreground application. You may need to add a short delay to make sure ristretto has finished launching before sending the keys. See pyautogui's keyboard documentation for more details about how to use it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...