内容简介:我的蓝牙鼠标(雷柏 MT750)使用 BLE(Bluetooth Low Energy) 连接笔记本时,时常遇到自动重连后电脑这边认为已连接,而鼠标那边灯自动灭掉,鼠标指针无反应的问题。在网上反复搜索 bluez 相关问题找到了许多类似问题,鼠标类型也集中在罗技、ThinkPad 等 BLE 鼠标上。偶然间发现每次重连后,如果手动用 bluetoothctl 发一个 “pair” 指令(会超时失败),就能令鼠标正常连接。给 bluez 报了一个 bug 后,我写了下面的简单脚本先绕过问题:保持在后台运行即可
我的蓝牙鼠标(雷柏 MT750)使用 BLE(Bluetooth Low Energy) 连接笔记本时,时常遇到自动重连后电脑这边认为已连接,而鼠标那边灯自动灭掉,鼠标指针无反应的问题。在网上反复搜索 bluez 相关问题找到了许多类似问题,鼠标类型也集中在罗技、ThinkPad 等 BLE 鼠标上。
偶然间发现每次重连后,如果手动用 bluetoothctl 发一个 “pair” 指令(会超时失败),就能令鼠标正常连接。给 bluez 报了一个 bug 后,我写了下面的简单脚本先绕过问题:
#!/usr/bin/python import dbus import dbus.mainloop.glib from gi.repository import GLib adapter = "hci0" device = "xx:xx:xx:xx:xx:xx" device_path = '/org/bluez/' + adapter + "/dev_" + device.replace(":", "_") dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) system_bus = dbus.SystemBus() device_object = system_bus.get_object('org.bluez', device_path) device_interface = dbus.Interface(device_object, 'org.bluez.Device1') def device_info(_arg0, event, _arg2): if event.get("Connected"): print("Mouse connected, attempt to pair...") try: device_interface.Pair() except dbus.exceptions.DBusException: pass system_bus.add_signal_receiver( device_info, dbus_interface='org.freedesktop.DBus.Properties', signal_name="PropertiesChanged", arg0='org.bluez.Device1') GLib.MainLoop().run()
保持在后台运行即可。我自己测试了一段时间,效果非常好。
PS: bluez 上游 bugzilla 堆满了各种没有回答的错误报告,目测不是那么好修的……
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 鼠标指针在Windows 10上滞后或冻结
- WPF 程序鼠标在窗口之外的时候,控件拿到的鼠标位置在哪里?
- 鼠标悬停动画效果
- wpf 模拟鼠标和键盘操作
- CSS3鼠标经过动画特效
- jQuery实现鼠标响应式淘宝动画效果示例
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Algorithms + Data Structures = Programs
Niklaus Wirth / Prentice Hall / 1975-11-11 / GBP 84.95
It might seem completely dated with all its examples written in the now outmoded Pascal programming language (well, unless you are one of those Delphi zealot trying to resist to the Java/.NET dominanc......一起来看看 《Algorithms + Data Structures = Programs》 这本书的介绍吧!