自己在玩dota的時(shí)候有時(shí)候喜歡邊玩游戲邊聽音樂,但是切換下一曲的時(shí)候必須得切出游戲,而切換音樂的熱鍵ctrl+alt+方向鍵在游戲的時(shí)候沒有用,好事蛋疼,今天試試使用python來實(shí)現(xiàn)鍵盤監(jiān)控切換下一曲,下面貼出代碼
import pythoncom, pyHook import win32gui,win32api,win32con Lcontrol_press = False Lmenu_press = False Left_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 True def 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 = OnKeyboardEvent hm.HookKeyboard() pythoncom.PumpMessages()
好了,把你的播放器設(shè)置為隨機(jī)播放就可以在游戲的時(shí)候按下ctrl+alt+左方向鍵就可以切換音樂啦(ctrl和alt也是左邊的)
順便說明下,那三個(gè)快捷鍵不是組合鍵,意思是你要先按下ctrl然后放開,在按下alt,最后按一下做方向鍵就切換音樂了.這三個(gè)鍵的順序不能按錯(cuò).
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
