在开发python的时候,我们有时候想监听USB插拔、按键事件。废话不多说,直接上代码吧,代码如下:
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
from ctypes.wintypes import MSG
import datetime
import ctypes
from ctypes.wintypes import MSG
import ctypes.wintypes as wintypes
NULL = 0
INVALID_HANDLE_VALUE = -1
DBT_DEVTYP_DEVICEINTERFACE = 5
DEVICE_NOTIFY_WINDOW_HANDLE = 0x00000000
DBT_DEVICEREMOVECOMPLETE = 0x8004
DBT_DEVICEARRIVAL = 0x8000
WM_DEVICECHANGE = 0x0219
WM_KEYDOWN = 0x0100
user32 = ctypes.windll.user32
RegisterDeviceNotification = user32.RegisterDeviceNotificationW
UnregisterDeviceNotification = user32.UnregisterDeviceNotification
class GUID(ctypes.Structure):
_pack_ = 1
_fields_ = [("Data1", ctypes.c_ulong),
("Data2", ctypes.c_ushort),
("Data3", ctypes.c_ushort),
("Data4", ctypes.c_
在开发python的时候,我们有时候想监听USB插拔、按键事件。废话不多说,直接上代码吧,代码如下:
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
from ctypes.wintypes import MSG
import datetime
import ctypes
from ctypes.wintypes import MSG
import ctypes.wintypes as wintypes
NULL = 0
INVALID_HANDLE_VALUE = -1
DBT_DEVTYP_DEVICEINTERFACE = 5
DEVICE_NOTIFY_WINDOW_HANDLE = 0x00000000
DBT_DEVICEREMOVECOMPLETE = 0x8004
DBT_DEVICEARRIVAL = 0x8000
WM_DEVICECHANGE = 0x0219
WM_KEYDOWN = 0x0100
user32 = ctypes.windll.user32
RegisterDeviceNotification = user32.RegisterDeviceNotificationW
UnregisterDeviceNotification = user32.UnregisterDeviceNotification
class GUID(ctypes.Structure):
_pack_ = 1
_fields_ = [("Data1", ctypes.c_ulong),
("Data2", ctypes.c_ushort),
("Data3", ctypes.c_ushort),
("Data4", ctypes.c_