Ubuntu中使用pyUSB读取鼠标或键盘的数据程序
参考 :http://www.orangecoat.com/how-to/read-and-decode-data-from-your-mouse-using-this-pyusb-hack
要注意的问题:
在ubuntu中USB的使用需要root权限。所以普通情况下即使程序没错也会导致USBError。解决的办法:在终端下以root方式打开python的IDE。Eclipse的pydev不能在root下打开,除非在root情况也装个pydev。最好是用spyder,虽然编辑起来没有eclipse方便,但是也很不错了。
如果程序运行错误而退出,会usb设备无反应,重新插拔usb即可。
import usb
dev = usb.core.find(idVendor= 0x24ae, idProduct = 0x2000)
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
interface = 0
endpoint = dev[0][(0,0)][0]
if dev.is_kernel_driver_active(interface) is True:
dev.detach_kernel_driver(interface)
usb.util.claim_interface(dev, interface)
collected = 0
attempts = 50
while collected <attempts:
try:
data = dev.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize)
collected += 1
print data
except usb.core.USBError as e:
data = None
if e.args == ('Operation timed out',):
continue
usb.util.release_interface(dev, interface)
dev.attach_kernel_driver(interface)
Ubuntu中使用pyUSB读取鼠标或键盘的数据程序的更多相关文章
- Selenium_Selenium WebDriver 中鼠标和键盘事件分析及扩展
在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击.双击.右击.拖拽等动作:或者键盘输入.快捷键使用.组合键使用等模拟键盘的操作.在 W ...
- Selenium WebDriver中一些鼠标和键盘事件的使用
转自:http://www.ithov.com/linux/133271.shtml 在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击 ...
- Selenium WebDriver 中鼠标和键盘事件分析及扩展(转)
本文将总结 Selenium WebDriver 中的一些鼠标和键盘事件的使用,以及组合键的使用,并且将介绍 WebDriver 中没有实现的键盘事件(Keys 枚举中没有列举的按键)的扩展.举例说明 ...
- 转:总结Selenium WebDriver中一些鼠标和键盘事件的使用
在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击.双击.右击.拖拽等动作:或者键盘输入.快捷键使用.组合键使用等模拟键盘的操作.在 W ...
- Selenium WebDriver 中鼠标和键盘事件分析及扩展[转载]
原文:http://www.ibm.com/developerworks/cn/java/j-lo-keyboard/ 概念 在使用 Selenium WebDriver 做自动化测试的时候,会经常模 ...
- 总结Selenium WebDriver中一些鼠标和键盘事件的使用
在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击.双击.右击.拖拽等动作:或者键盘输入.快捷键使用.组合键使用等模拟键盘的操作.在 W ...
- Selenium WebDriver 中鼠标和键盘事件分析及扩展
[From] http://www.51testing.com/html/18/631118-861557.html 在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和 ...
- Ubuntu中类似QQ截图的截图工具并实现鼠标右键菜单截图
@ 目录 简介: 安装: 设置快捷键: 实现鼠标右键菜单截图: 简介: 在Windows中用惯了强大易用的QQ截图,会不习惯Ubuntu中的截图工具. 软件名为火焰截图,功能类似QQ截图,可以设置快捷 ...
- 在C#中使用全局鼠标、键盘Hook
今天,有个同事问我,怎样在C#中使用全局钩子?以前写的全局钩子都是用unmanaged C或C++写个DLL来实现,可大家都知道,C#是基于.Net Framework的,是managed,怎么实现全 ...
随机推荐
- Apache 下SVN项目管理使用说明
Apache 下SVN项目管理使用说明 (1)Apaceh和SVN先要装好. (2)在apache的目录下找到httpd.conf文件,在最后一行增加如下配置 Include conf/svn.pro ...
- arcengine C# 读写lyr(转)
写lyr { IFeatureLayer LineLayer = axMapControl1.get_Layer(0) as IFeatureLayer; ILayerFile ...
- Redhat 使用中文安装后更换为英文的设定
vi /etc/sysconfig/i18n将LANG改为LANG=en_US.UTF-8保存退出,重新reboot
- OpenCV源码阅读(3)---base.hpp
base.h处于core模块中,是OpenCV的核心类.其作用是定义了OpenCV的基本错误类型,在程序运行出现错误是抛出错误,防止数据溢出.总而言之,其功能主要是考虑程序的健壮性. 头文件 #ifn ...
- 在Windows 上的 Python
在 Windows 上, 安装 Python 有两种选择. ActiveState 制作了一个 Windows 上的 Python 安装程序称为 ActivePython, 它包含了一个完整的 Pyt ...
- OutputStream窥探
/* * Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETA ...
- 修练8年C++面向对象程序设计之体会
http://pcedu.pconline.com.cn/empolder/gj/c/0504/609482_1.html
- sh.exe": grunt: command not found
今天在git命令行工具中使用 grunt的时候,总是提示我找不到grunt命令,如: sh.exe": grunt: command not found 但是我运行 npm install ...
- 12 Useful “df” Commands to Check Disk Space in Linux
On the internet you will find plenty of tools for checking disk space utilization in Linux. However, ...
- sdut 2831 Euclid (几何)
题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2831 题意:给a, b, c, d, ...