自己在玩dota的時(shí)候有時(shí)候喜歡邊玩游戲邊聽音樂,但是切換下一曲的時(shí)候必須得切出游戲,而切換音樂的熱鍵ctrl+alt+方向鍵在游戲的時(shí)候沒有用,好事蛋疼,今天試試使用python來實(shí)現(xiàn)鍵盤監(jiān)控切換下一曲,下面貼出代碼
import pythoncom, pyHookimport win32gui,win32api,win32con Lcontrol_press = FalseLmenu_press = FalseLeft_press = False def OnKeyboardEvent(event): global Lcontrol_press #在函數(shù)里面使用全局變量的時(shí)候要加上global關(guān)鍵字 global Lmenu_press #要不然會(huì)出錯(cuò) global Left_press print 'Key:', event.Key if (event.Key == "Lcontrol"): Lcontrol_press = True elif(event.Key == "Lmenu"): Lmenu_press = True elif(event.Key == "Left"): Left_press =True handel_key() return Truedef handel_key() : global Lcontrol_press global Lmenu_press global Left_press if(Lcontrol_press and Lmenu_press and Left_press): win32api.keybd_event( 0xB0,win32con.VK_MEDIA_NEXT_TRACK,0,0) Lcontrol_press = False Lmenu_press = False Left_press = False hm = pyHook.HookManager()hm.KeyDown = OnKeyboardEventhm.HookKeyboard()pythoncom.PumpMessages()
好了,把你的播放器設(shè)置為隨機(jī)播放就可以在游戲的時(shí)候按下ctrl+alt+左方向鍵就可以切換音樂啦(ctrl和alt也是左邊的)
順便說明下,那三個(gè)快捷鍵不是組合鍵,意思是你要先按下ctrl然后放開,在按下alt,最后按一下做方向鍵就切換音樂了.這三個(gè)鍵的順序不能按錯(cuò).
新聞熱點(diǎn)
疑難解答
圖片精選