小智 14
xinput --query-state <mouse_id>
Run Code Online (Sandbox Code Playgroud)
这为您提供了所有鼠标按钮的状态,如下所示:
2 classes :
ButtonClass
button[1]=up
button[2]=up
button[3]=up
button[4]=up
button[5]=up
button[6]=up
button[7]=up
button[8]=up
button[9]=up
button[10]=up
button[11]=up
button[12]=up
button[13]=up
button[14]=up
button[15]=up
button[16]=up
ValuatorClass Mode=Relative Proximity=In
valuator[0]=313
valuator[1]=667
valuator[2]=-20
Run Code Online (Sandbox Code Playgroud)
mouse_id 可以从:
xinput --list
Run Code Online (Sandbox Code Playgroud)
这是一个小鼠标按钮观察器脚本:
#!/bin/bash
MOUSE_ID=$(xinput --list | grep -i -m 1 'mouse' | grep -o 'id=[0-9]\+' | grep -o '[0-9]\+')
STATE1=$(xinput --query-state $MOUSE_ID | grep 'button\[' | sort)
while true; do
sleep 0.2
STATE2=$(xinput --query-state $MOUSE_ID | grep 'button\[' | sort)
comm -13 <(echo "$STATE1") <(echo "$STATE2")
STATE1=$STATE2
done
Run Code Online (Sandbox Code Playgroud)
您可能需要将 MOUSE_ID 检测字符串('鼠标')更改为其他内容。
您可以使用命令行工具xev
找出 X 环境中鼠标按钮的状态。
$ xev
...
ButtonPress event, serial 36, synthetic NO, window 0x3800001,
root 0x86, subw 0x0, time 319064320, (164,14), root:(166,101),
state 0x0, button 1, same_screen YES
ButtonRelease event, serial 36, synthetic NO, window 0x3800001,
root 0x86, subw 0x0, time 319064439, (164,14), root:(166,101),
state 0x100, button 1, same_screen YES
ButtonPress event, serial 36, synthetic NO, window 0x3800001,
root 0x86, subw 0x0, time 319065208, (164,14), root:(166,101),
state 0x0, button 1, same_screen YES
ButtonRelease event, serial 36, synthetic NO, window 0x3800001,
root 0x86, subw 0x0, time 319065337, (164,14), root:(166,101),
state 0x100, button 1, same_screen YES
ButtonPress event, serial 36, synthetic NO, window 0x3800001,
root 0x86, subw 0x0, time 319066059, (164,14), root:(166,101),
state 0x0, button 1, same_screen YES
Run Code Online (Sandbox Code Playgroud)
但是这些信息只能让您部分地找到解决方案。您要从上面提取的关键信息是哪个数字与鼠标上的特定按钮相关联。在我的示例中,我按下左按钮“按钮 1”。
您可以使用此工具来设置与按下的按钮相关联的操作。您甚至可以设置一个需要按键或什至同时按下一个键 + 按钮的规则。
您需要首先确保安装了 xbindkeys 软件包。
然后您需要运行以下命令,仅一次,以创建模板 xbindkeys 配置文件。
$ xbindkeys --defaults > /home/saml/.xbindkeysrc
Run Code Online (Sandbox Code Playgroud)
创建文件后,您可以在文本编辑器中打开它并添加如下规则:
"xterm"
b:3
Run Code Online (Sandbox Code Playgroud)
该规则规定我们要在xterm
按下按钮 3 时运行程序。“按钮 3”是我的鼠标右键。
通过上述更改,如果 xbindkeys 已经在运行,我们需要杀死它,然后重新启动它。
$ killall xbindkeys
$ xbindkeys
Run Code Online (Sandbox Code Playgroud)
现在,每当我单击鼠标右键时,xterm
都会运行此程序,将执行此操作。
小智 5
如果您只想在鼠标单击(或滚轮事件)时在 xterm 中运行 bash 命令,您可以尝试以下示例:
$ echo -e "\e[?1000h"
$ while read -n 6; do echo hellowworld; done
Run Code Online (Sandbox Code Playgroud)
这是用于轮子事件(用于单击设置 12)
归档时间: |
|
查看次数: |
29362 次 |
最近记录: |