如何在python中模拟按键?我也想同时按下多个键。
就像是:
keystroke('CTRL+F4')
要么
keystroke('Shift+A')
尽管它特定于X,但是您可以安装xautomation软件包(apt-get install xautomation在基于Debian的系统上)并用于xte模拟按键,例如:
apt-get install xautomation
xte
from subprocess import Popen, PIPE control_f4_sequence = '''keydown Control_L key F4 keyup Control_L ''' shift_a_sequence = '''keydown Shift_L key A keyup Shift_L ''' def keypress(sequence): p = Popen(['xte'], stdin=PIPE) p.communicate(input=sequence) keypress(shift_a_sequence) keypress(control_f4_sequence)