我正在尝试建立一个python程序,每当我在键盘上按下3个特定键之一时,我就会对它进行计数/分组。然后,当给出另一个输入时,这三个特定组的值记录在表/电子表格中。
例如,每当我按“ l”键时,我希望增加“ alpha”的值,因此,如果我在键盘上按3次“ l”,则希望打印为“ alpha”的值是3 。
到目前为止,我已经设法编写了代码,可以在我按3个特定的键时成功地增加三个独立的组,但是我想不出以后记录值的好方法。
import keyboard
shot_pressed1 = 0
shot_pressed2 = 0
shot_pressed3 = 0
def on_press_reaction1(event):
global shot_pressed1
if event.name == 's':
shot_pressed1 += 1
print("alpha %d"%shot_pressed1)
def on_press_reaction2(event):
global shot_pressed2
if event.name == 'm':
shot_pressed2 += 1
print("beta %d"%shot_pressed2)
def on_press_reaction3(event):
global shot_pressed3
if event.name == 'l':
shot_pressed3 += 1
print("theta %d"%shot_pressed3)
keyboard.on_press(on_press_reaction1)
keyboard.on_press(on_press_reaction2)
keyboard.on_press(on_press_reaction3)
while True:
pass
我知道这可能是一个很简单的问题,但我对python还是有点陌生。
我不明白为什么您要使用Excel标记。
将熊猫数据框浏览到_excel以将数据导出为这种格式。