Python编程.Bluetooth HID Mouse and Keyboard(三)
来源:互联网 发布:阿里云 华东2 编辑:程序博客网 时间:2024/06/16 10:09
调用SDP Helper接口非常简单,基本上跟Sample Code差不多,只不过代码换成了Python编程。
#!/usr/bin/env pythonimport ctypes,oshidd_report_desc = bytearray( [0x05, 0x01,# UsagePage GenericDesktop0x09, 0x02,# Usage Mouse0xA1, 0x01,# Collection Application0x85, 0x01,# REPORT ID: 10x09, 0x01,# Usage Pointer0xA1, 0x00,# Collection Physical0x05, 0x09,# UsagePage Buttons0x19, 0x01,# UsageMinimum 10x29, 0x03,# UsageMaximum 30x15, 0x00,# LogicalMinimum 00x25, 0x01,# LogicalMaximum 10x75, 0x01,# ReportSize 10x95, 0x03,# ReportCount 30x81, 0x02,# **Input data variable absolute0x75, 0x05,# ReportSize 50x95, 0x01,# ReportCount 10x81, 0x01,# **InputConstant (padding)0x05, 0x01,# UsagePage GenericDesktop0x09, 0x30,# Usage X0x09, 0x31,# Usage Y0x09, 0x38,# Usage ScrollWheel0x15, 0x81,# LogicalMinimum -1270x25, 0x7F,# LogicalMaximum +1270x75, 0x08,# ReportSize 80x95, 0x02,# ReportCount 30x81, 0x06,# **Input data variable relative0xC0, 0xC0,# EndCollection EndCollection0x05, 0x01,# UsagePage GenericDesktop0x09, 0x06,# Usage Keyboard0xA1, 0x01,# Collection Application0x85, 0x02,# REPORT ID: 20xA1, 0x00,# Collection Physical0x05, 0x07,# UsagePage Keyboard0x19, 0xE0,# UsageMinimum 2240x29, 0xE7,# UsageMaximum 2310x15, 0x00,# LogicalMinimum 00x25, 0x01,# LogicalMaximum 10x75, 0x01,# ReportSize 10x95, 0x08,# ReportCount 80x81, 0x02,# **Input data variable absolute0x95, 0x08,# ReportCount 80x75, 0x08,# ReportSize 80x15, 0x00,# LogicalMinimum 00x25, 0x65,# LogicalMaximum 1010x05, 0x07,# UsagePage Keycodes0x19, 0x00,# UsageMinimum 00x29, 0x65,# UsageMaximum 1010x81, 0x00,# **Input DataArray0xC0, 0xC0,# EndCollection ])class HiddInfo(ctypes.Structure): _fields_ = (('service_name', ctypes.c_char_p), ('description', ctypes.c_char_p), ('provider', ctypes.c_char_p), ('desc_data', ctypes.c_char_p), ('desc_len', ctypes.c_uint), ('sub_class', ctypes.c_uint))HiddInfoPtr = ctypes.POINTER(HiddInfo)class Sdp: def __init__(self): self.dll = ctypes.CDLL(os.path.abspath('libbthidd.so')) return def CreateRecord(self, handle=0xffffffff): return self.dll.SdpCreateRecord(ctypes.c_uint(handle)) def DestroyRecord(self, record): return self.dll.SdpDestroyRecord(ctypes.c_void_p(record)) def MakeUpHidRecord(self, record, info): return self.dll.SdpMakeUpHidRecord(ctypes.c_void_p(record), HiddInfoPtr(info)) def RegisterRecord(self, record): return self.dll.SdpRegisterRecord(ctypes.c_void_p(record)) def UnregisterRecord(self, record): return self.dll.SdpUnregisterRecord(ctypes.c_void_p(record)) passdef main_entry(): info = HiddInfo() info.service_name = 'My Virtual Mouse and Keyboard' info.description = 'Bluetooth HID Mouse and Keyboard' info.provider = 'Huipeng Zhao' info.desc_data = str(hidd_report_desc) info.desc_len = len(hidd_report_desc) info.sub_class = 0x80 sdp = Sdp() record = sdp.CreateRecord() sdp.MakeUpHidRecord(record, info) sdp.RegisterRecord(record) sdp.DestroyRecord(record) returnif __name__ == '__main__': main_entry() pass
Sdp类会在初始化函数中打开libbthidd.so动态库,因此Python脚本与libbthidd.so得放在同一个目录下。
0 0
- Python编程.Bluetooth HID Mouse and Keyboard(三)
- Python编程.Bluetooth HID Mouse and Keyboard(一)
- Python编程.Bluetooth HID Mouse and Keyboard(二)
- Python编程.Bluetooth HID Mouse and Keyboard(四)
- HID - Keyboard键盘和Mouse鼠标实例
- The Mouse and the Keyboard
- Firefox Keyboard and Mouse Shortcuts
- c8051f320实现HID类(usb keyboard, usb mouse, usb joystick)
- 《基于MFC的OpenGL编程》Part 6 Keyboard and Mouse Control
- 《基于MFC的OpenGL编程》Part 5 Keyboard and Mouse Control
- Processing Global Mouse and Keyboard Hooks in C#
- Processing Global Mouse and Keyboard Hooks in C#
- Processing Global Mouse and Keyboard Hooks in C#
- Windows 8: Tips and Tricks for mouse/keyboard users
- Put the Mouse Down and Step Away from the Keyboard
- [SYNERGY] A mouse and keyboard sharing software on cross-platform
- Put the Mouse Down and Step Away from the Keyboard
- bluetooth编程三 socket
- kmalloc
- ZSL (zero shutter lag)
- 从表结构到项目实体类自动生成问题
- struts2标签内计算取小数点后两位
- 求最小公倍数的两种方法!!!
- Python编程.Bluetooth HID Mouse and Keyboard(三)
- lua print在android系统上的问题
- 判断域名格式合法性
- [转载] ArrayList的使用方法
- 浏览器遏止新窗口(window.open或新窗的form提交)
- 南乡一剪梅
- How Oracle Locking Works - First
- SVN账号管理
- 给TextView加上多彩效果:改变部分字体的大小和颜色