2013-02-11 96 views
0

我發現這兩個API在http://linux.die.net/man/3/xgetpointermapping。我認爲它們可以用來在Linux或Mac系統上交換鼠標按鈕。我用它以下面的方式:使用XGetPointerMapping/XSetPointerMapping交換鼠標按鈕

  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

按鈕號存儲爲無符號字符,但不作爲字符存儲。 將「1」和「3」更改爲1和3.

您的代碼將它們映射到按鈕49和51,並確實會影響按鈕1和3無法使用。

+0

感謝您的回答。我將「1」更改爲1,將「3」更改爲3.但XSetPointerMapping返回0.即使在sudo下運行,它也會返回零,並且不會影響鼠標按鈕。 0作爲返回值的含義是什麼?我對X Windows編程頗爲陌生。 – doptimusprime 2013-02-12 04:03:40

+0

爲我工作,我得到零回報,所以我認爲它沒問題。嘗試打印地圖值來檢查它們。唯一的其他改變是使用無符號字符。 – parkydr 2013-02-12 06:25:25

+0

同樣的程序對你來說工作正常嗎?我想念curdisp嗎?我在Mac OS上運行此代碼(Mountain Lion 10.7.4)。在這臺機器上,它沒有運行。我還沒有在linux機器上測試過。 – doptimusprime 2013-02-12 07:53:54