使用XGetPointerMapping / XSetPointerMapping交换鼠标按钮

时间:2013-02-11 12:09:27

标签: linux x11

我在http://linux.die.net/man/3/xgetpointermapping找到了这两个API。我认为它们可以用来交换linux或mac系统上的鼠标按钮。我用以下方式使用它:

            Display *   curdisp;    // Current display.
    char        curmap[MAX_NUM];// Current mapping.
    int         nmap;       // number of mappings.

curdisp = XOpenDisplay(NULL);

nmap    = XGetPointerMapping(curdisp, curmap, MAX_NUM);
if(!nmap)
    return -1;

if(curmap[0] == '1' && curmap[2] == '3') {
    curmap[0] = '3';
    curmap[2] = '1';
} else {
    curmap[0] = '1';
    curmap[2] = '3';
}

//Set the mapping.
nmap    = XSetPointerMapping(curdisp, curmap, nmap);

但是调用XSetPointerMapping返回0并且对鼠标按钮没有影响。 任何人都可以举一些使用XSetPointerMapping交换鼠标按钮的例子吗?或如何正确使用它?它会立即起作用吗?

使用的操作系统是Mac OS X 10.7.4。

1 个答案:

答案 0 :(得分:1)

按钮编号存储为unsigned char,但不存储为字符。 将“1”和“3”更改为1和3。

您的代码将它们映射到按钮49和51,并确实影响使按钮1和3无法使用的按钮。