python按键盘上哪个键运行_python通过按下键盘特定按键,开始运行python文件
一、目的
通過按下鍵盤特定按鍵,開始運行python文件
二、code
from pykeyboard import PyKeyboardEvent
from pykeyboard import *
from pymouse import PyMouseEvent
import PyHook3
import hello
class Clickonacci(PyKeyboardEvent):
def __init__(self):
PyKeyboardEvent.__init__(self)
def tap(self, keycode, character, press):
'''Print Fibonacci numbers when the left click is pressed.'''
if character == 'z':
if press:
print ('hello2')
# python 文件
hello.hello()
else: # Exit if any other mouse button used
print(character)
C = Clickonacci()
C.run()
靠譜教程
https://blog.csdn.net/qq_38839677/article/details/83374219
主要包 pykeyboard,pymouse, pyhook3(是模擬鍵盤輸入和鼠標點擊的庫,也可以讀取鍵盤和鼠標的信息,pyhook3適應python3, 如果pyhook是適應python2的會報錯)。pyhook3包含pykeyboard,pymouse。
(function:鍵盤是tap,鼠標是click)
實現這個交互過程要求安裝兩個包。先安裝pyHook,再安裝PyUserInput。
pyHook是適應python2的,
程序報錯。前提并不知道要和python3.7匹配,程序運行的時候報錯:不能找到滿足pyUserput的版本
報錯2
非常有用的參考:
https://blog.csdn.net/qq_38161040/article/details/87920192
第一步:
安裝pyHook3之前要安裝pywin32
pywin32方便python開發者快速調用windows API的一個模塊庫。
pip install pywin32 (不行)
pip3 install -i https://pypi.doubanio.com/simple/ pywin32
https://jingyan.baidu.com/article/6b97984de993431ca2b0bfc2.html
pywin32還提供了其他2個相當重要的模塊:
第一個是win32gui,這個模塊內定義了一些有關圖形操作的API,例如FindWindow
第二個是win32con,這個模塊內定義了windows API內的宏,例如MessageBox內的MB_OK
第二步:
pyHook3安裝:
安裝之前還要先裝兩個東西(windows怎么這么麻煩)
參考https://blog.csdn.net/qq_38161040/article/details/87928583
參考vc++ 14.0
https://blog.csdn.net/weixin_42057852/article/details/80857948
1 : swig安裝;
2 : Microsoft
Visual C++ 14.0 is required問題解決;
這兩步解決了之后直接pip install
PyHook3就可以了。(也沒有這位說的這么容易,遇到什么錯忘了,如果可以就直接pip install;不可以就下面這個)
下載whl安裝文件
下載鏈接: https://www.cnblogs.com/Denon-CAT/p/12771357.html
Win+r , cmd 進入相應路徑,
pip install 文件名.whl
第三步:
安裝PyUserInput
找到python/scripts 然后pip install PyUserInput
C:\Users\57156\AppData\Local\Programs\Python\Python37\Scripts
pip install PyUserInput
附錄:其他方法
pyhook監聽鼠標事件和鍵盤事件
https://blog.csdn.net/matrix_google/article/details/71512495
下載 msvcrt.dll
https://cn.dll-files.com/download/14c8b0d022cdd56939e5385cbcab60a6/msvcrt.dll.html?c=NjAxcXdLR2E0RmpjMUNlTjVzS3ppZz09
放在system32文件夾下
win+R
regsvr32 msvcrt.dll
from tkinter import *
import time
import random
https://zhidao.baidu.com/question/266291349.html
鍵盤各鍵對應的ASCII碼值(包括鼠標和鍵盤所有的鍵)
ENTER是13
使用python監聽、模擬鼠標鍵盤事件
https://www.cnblogs.com/axiong/p/5937203.html
python模擬鍵盤觸發
https://blog.csdn.net/bo512958706/article/details/79845303
(注意:和本文目的不一樣)
通過使用enter鍵模擬點擊確定按鈕
https://blog.csdn.net/weixin_34220963/article/details/92407007
原文鏈接:https://blog.csdn.net/qq_38221026/article/details/106490757
總結
以上是生活随笔為你收集整理的python按键盘上哪个键运行_python通过按下键盘特定按键,开始运行python文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 比特币官方客户端钱包是用什么语言开发的_
- 下一篇: mkfontscale没有这个命令_那些