I sometimes like playing games while listening to music while playing DotA. But to switch the next song must be cut out of the game, and switch the hot key ctrl+alt+ in the game is no use, good egg pain, today try to use Python to implement keyboard monitoring switch next song, The following code is posted
import pythoncom, Pyhook import win32gui,win32api,win32con lcontrol_press = False lmenu_ Press = False left_press = False def onkeyboardevent (event): Global lcontrol_press #在函数里面使用全局变量的时候要加上global关键字 Globa L lmenu_press #要不然会出错 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 Lmen U_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.HOOKM Anager () hm. KeyDown = Onkeyboardevent hm. Hookkeyboard () pythoncom. Pumpmessages ()
Okay, set your player to a random play can be in the game when you press ctrl+alt+ left ARROW keys can switch music (CTRL and ALT are also left)
by the way, the three shortcuts are not key combinations, meaning you have to hold down CTRL and then let go. When you press ALT, the last button to do is switch the music. The order of these three keys cannot be pressed incorrectly.