001

#include

002

#include

003

#include

004

#include

005

#include

006

// 以下代码源自

007

// [需要在文本控制台下运行,才能获取到数据,在ubuntu 8.10 GNOME界面只能收到1个字节数据0xfa][luther.gliethttp]

008

// libminigui-1.6.10/src/ial/native/native.c

009

// InitIAL==>__mg_cur_input = inputs{"console", InitNativeInput, TermNativeInput},

010

// mousedev = mousedev_IMPS2;

011

// input->update_mouse = mouse_update;

012

/* Mouse button bits*/

013

#define WHEEL_UP 0x10

014

#define WHEEL_DOWN 0x08

015

#define BUTTON_L 0x04

016

#define BUTTON_M 0x02

017

#define BUTTON_R 0x01

018

#define SCALE 3

/* default scaling factor for acceleration */

019

#define THRESH 5

/* default threshhold for acceleration */

020

static

int

xpos;

/* current x position of mouse */

021

static

int

ypos;

/* current y position of mouse */

022

static

int

minx;

/* minimum allowed x position */

023

static

int

maxx;

/* maximum allowed x position */

024

static

int

miny;

/* minimum allowed y position */

025

static

int

maxy;

/* maximum allowed y position */

026

static

int

buttons;

/* current state of buttons */

027

static

int

scale

=

SCALE;

/* acceleration scale factor */

028

static

int

thresh

=

THRESH;

/* acceleration threshhold */

029

static

int

mouse_update(

int

dx

,

int

dy

,

int

dz);

030

static

int

IMPS2_Read (

int

*

dx

,

int

*

dy

,

int

*

dz

,

int

*bp);

031

static

void

mouse_setposition (

int

newx

,

int

newy);

032

static

void

mouse_setrange (

int

newminx

,

int

newminy

,

int

newmaxx

,

int

newmaxy);

033

int

mouse_fd;

034

int

main(

void)

035

{

036

int

dx

,

dy

,

dz;

037

static

unsigned

char

imps2_param

[]

=

{

243

,

200

,

243

,

100

,

243

,

80

};

//,242};

038

// 来自vnc4的xc/programs/Xserver/hw/xfree86/input/mouse/mouse.c==>PROT_IMPS2

039

const

char

*

mdev

=

"/dev/input/mice";

040

mouse_fd

=

open (

mdev

,

O_RDWR);

// | O_NONBLOCK);

041

if (

mouse_fd

<

0)

{

042

printf(

"[luther.gliethttp]: RW error [please use root user]: %s

/n

"

,

mdev);

043

mouse_fd

=

open (

mdev

,

O_RDONLY);

// | O_NONBLOCK);

044

if (

mouse_fd

<

0)

045

return

-

1;

046

}

else

{

047

write (

mouse_fd

,

imps2_param

,

sizeof (

imps2_param));

// 初始化序列, 这样可以读取4个字节数据

048

// 0x80用来表示滚轮向上还是向下滚动.de>

049

de

>

// 0xa0表示滚轮向上滚动的同时中键按下

050

de

>

051

de

>

printf(

"[luther.gliethttp]: imps2_param ok!

/n

");

052

}

053

mouse_setrange(

0

,

0

,

1024

,

768);

054

for (;;)

{

055

IMPS2_Read(

&

dx

,

&

dy

,

&

dz

,

&

buttons);

056

mouse_update(

dx

,

dy

,

dz);

057

mouse_setposition(

xpos

,

ypos);

058

printf(

"[%04d,%04d,0x%04x]

/n

"

,

xpos

,

ypos

,

buttons);

059

}

060

return

0;

061

}

062

static

int

IMPS2_Read (

int

*

dx

,

int

*

dy

,

int

*

dz

,

int

*bp)

063

{

064

static

unsigned

char

buf

[

5

];

065

static

int

buttons

[

7

]

=

{

0

,

1

,

3

,

0

,

2

,

0

,

0

};

// 1左键,2中键,3右键

066

static

int

nbytes;

067

int n;

068

while ((n

=

read (

mouse_fd

,

&

buf

[

nbytes

],

4

-

nbytes)))

{

069

if (n

<

0)

{

070

if (

errno

==

EINTR)

071

continue;

072

else

073

return

-

1;

074

}

075

nbytes

+= n;

076

if (

nbytes

==

4)

{

077

int

wheel;

078

// printf("[luther.gliethttp]: %02x %02x %02x %02x/n", buf[0], buf[1], buf[2], buf[3]);

079

if ((

buf

[

0

]

&

0xc0)

!=

0)

{

080

buf

[

0

]

=

buf

[

1

];

081

buf

[

1

]

=

buf

[

2

];

082

buf

[

2

]

=

buf

[

3

];

083

nbytes

=

3;

084

return

-

1;

085

}

086

/* FORM XFree86 4.0.1 */

087

*bp

=

buttons

[(

buf

[

0

]

&

0x07

)];

088

*

dx

= (

buf

[

0

]

&

0x10)

?

buf

[

1

]

-

256

:

buf

[

1

];

089

*

dy

= (

buf

[

0

]

&

0x20)

?

-(

buf

[

2

]

-

256)

:

-

buf

[

2

];

090

/* Is a wheel event? */

091

if ((

wheel

=

buf

[

3

])

!=

0)

{

092

if(

wheel

>

0x7f)

{

093

*bp

|=

WHEEL_UP;

094

}

095

else

{

096

*bp

|=

WHEEL_DOWN;

097

}

098

}

099

*

dz

=

0;

100

nbytes

=

0;

101

return

1;

102

}

103

}

104

return

0;

105

}

106

static

int

mouse_update(

int

dx

,

int

dy

,

int

dz)

107

{

108

int

r;

109

int

sign;

110

sign

=

1;

111

if (

dx

<

0)

{

112

sign

=

-

1;

113

dx

=

-

dx;

114

}

115

if (

dx

>

thresh)

116

dx

=

thresh

+ (

dx

-

thresh)

*

scale;

117

dx

*=

sign;

118

xpos

+=

dx;

119

if(

xpos

<

minx )

120

xpos

=

minx;

121

if(

xpos

>

maxx )

122

xpos

=

maxx;

123

sign

=

1;

124

if (

dy

<

0)

{

125

sign

=

-

1;

126

dy

=

-

dy;

127

}

128

if (

dy

>

thresh)

129

dy

=

thresh

+ (

dy

-

thresh)

*

scale;

130

dy

*=

sign;

131

ypos

+=

dy;

132

if (

ypos

<

miny )

133

ypos

=

miny;

134

if (

ypos

>

maxy )

135

ypos

=

maxy;

136

return

1;

137

}

138

static

void

mouse_setposition (

int

newx

,

int

newy)

139

{

140

if (

newx

<

minx)

141

newx

=

minx;

142

if (

newx

>

maxx)

143

newx

=

maxx;

144

if (

newy

<

miny)

145

newy

=

miny;

146

if (

newy

>

maxy)

147

newy

=

maxy;

148

if (

newx

==

xpos

&&

newy

==

ypos)

149

return;

150

xpos

=

newx;

151

ypos

=

newy;

152

}

153

static

void

mouse_setrange (

int

newminx

,

int

newminy

,

int

newmaxx

,

int

newmaxy)

154

{

155

minx

=

newminx;

156

miny

=

newminy;

157

maxx

=

newmaxx;

158

maxy

=

newmaxy;

159

mouse_setposition ((

newminx

+

newmaxx)

/

2

, (

newminy

+

newmaxy)

/

2);

160

}

161

static

int

mouse_getbutton (

void)

162

{

163

return

buttons;

164

}

165

static

void

mouse_getxy (

int

*

x

,

int

*

y)

166

{

167

*

x

=

xpos;

168

*

y

=

ypos;

169

}

170

171

172

本文来自

CSDN

博客,转载请标明出处:

http

:

//blog.csdn.net/linucos/archive/2010/03/31/5436767.aspx

linux如何使用鼠标数据的,浅析linux中鼠标数据读取相关推荐

  1. Linux操作系统基础理论(3)-----浅析Linux 与Minix 下进程实现的异同

    Linux操作系统基础理论(3)-----浅析Linux 与Minix 下进程实现的异同 目录 摘要:... 1 1.     引言... 1 1.1  Minix简介... 1 1.2  Linux ...

  2. 表间数据复制--SELECT表中的数据插入到新的表中(ORACLE,MSSQL)

    表间数据复制--SELECT表中的数据插入到新的表中 --在Oracle 9i中 CREATE TABLE scott.test AS (SELECT DISTINCT empno,ename,hir ...

  3. sql数据透视_SQL Server中的数据科学:取消数据透视

    sql数据透视 In this article, in the series, we'll discuss understanding and preparing data by using SQL ...

  4. 如何将cell元胞中的数据转化为矩阵中的数据

    将cell中的数据转化成为矩阵中的数据只需用cell2mat函数即可 运行后得到的结果如下:

  5. linux 中kafka发送数据,C++ 向kafka中发送数据

    kafka是一个分布式流处理的平台,通过kafka我们可以发布和订阅流式记录.有关kafka的介绍可以参考官网或者这篇文章https://juejin.im/post/6844903495670169 ...

  6. 浅析WebRtc中视频数据的收集和发送流程

    前言 本文是基于PineAppRtc开源项目https://github.com/thfhongfeng/PineAppRtc 因为一个需求,我们需要将一个视频流通过WebRtc发送出去,所以就研究一 ...

  7. 浅析 Hadoop 中的数据倾斜

    最近几次被问到关于数据倾斜的问题,这里找了些资料也结合一些自己的理解. 在并行计算中我们总希望分配的每一个task 都能以差不多的粒度来切分并且完成时间相差不大,但是集群中可能硬件不同,应用的类型不同 ...

  8. springbatch apache-activemq 整合(往mq中put数据,从mq中take数据)

    简单测试如下: 1:收下下载apache-activemq-5.14.4 解压apache-activemq-5.14.4\bin\win64,运行activemq.bat 启动本地MQ服务器. 通过 ...

  9. python导入excel数据-如何把python中的数据导入excel

    python将数据导入excel的方法:1.在python官网下载xlrd第三方库:2.利用xlrd中的open_workbook函数读入excel文件,即可在python中导入excel数据. 一. ...

  10. python处理pdf提取指定数据_python从PDF中提取数据的示例

    01 前言 数据是数据科学中任何分析的关键,大多数分析中最常用的数据集类型是存储在逗号分隔值(csv)表中的干净数据.然而,由于可移植文档格式(pdf)文件是最常用的文件格式之一,因此每个数据科学家都 ...

最新文章

  1. Android WebView 与 JS 交互
  2. jQuery的Autocomplete插件
  3. boost::contract模块实现base types的测试程序
  4. [Linux]结合awk删除hdfs指定日期前的数据
  5. Oracle报错:类型长度大于最大值解决办法
  6. JavaScript方法
  7. .NET的一点历史故事:擦肩而过的机遇
  8. CSS文件开头到底声明@charset utf-8
  9. 非IE浏览器下让界面变灰色
  10. node中使用shell脚本
  11. 计算机博弈程序python_程序员大神们的经典编程语录
  12. 引入Google新技术 Picasa2发布
  13. 求你们不要再问我录屏软件了,这些电脑、手机录屏软件全给你们!
  14. VTK Camera
  15. r语言导入spss数据_R语言如何导入数据
  16. 股指期货真是个好东西
  17. 【Ubuntu 安装】Ubuntu20.04和Win10双系统安装指南
  18. 四元数在旋转的运用-圆形烟火弹道轨迹
  19. 电影赏析 002《毒战》
  20. java flv转mp3_java调用FFmpeg及mencoder转换视频为FLV并截图

热门文章

  1. python计算组合数_python排列组合算法
  2. OpenCV精进之路(十四):图像矫正技术深入探讨
  3. 【操作系统】处理机调度与死锁(三)
  4. Tensorflow中的RNN个人备忘
  5. opencv基础:相机参数标定(camera calibration)及标定结果如何使用
  6. 云南省电子计算机高级,计算机基础知识-云南省电子信息高级技工学校.ppt
  7. 4十4十4写成乘法算式_小学数学二年级下册数学1-4单元知识点复习提前准备才能考的更好...
  8. SECS/GEM series: Protocol Layer
  9. C++ 智能指针后面 . 与 -> 运算符的一点体会
  10. 洛谷 P2622 关灯问题II (状态压缩+BFS)