You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
from threading import Thread
from pynput import keyboard # pip install pynput
from Audio_record import AudioRecord
from Screenshot_record import Screenshot
def hotkey ( ) :
""" 热键监听 """
with keyboard . Listener ( on_press = on_press ) as listener :
listener . join ( )
def on_press ( key ) :
try :
video . terminate ( )
if key . char == ' t ' : # t键, 录制结束, 保存音视频
audio . stop_flag = True
elif key . char == ' k ' : # k键, 录制中止, 删除文件
audio . stop_flag = True
audio . kill = True
video . unlink ( ' test.mp4 ' )
except Exception as e :
print ( e )
key_thread = Thread ( target = hotkey , daemon = True )
audio = AudioRecord ( )
video = Screenshot ( )
key_thread . start ( )
video . record ( ' test.mp4 ' )