首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我按下竹子墨水笔的顶部按钮时,我怎么能运行命令呢?

当我按下竹子墨水笔的顶部按钮时,我怎么能运行命令呢?
EN

Unix & Linux用户
提问于 2020-02-26 12:35:32
回答 1查看 477关注 0票数 1

我一直在尝试运行一个命令,当我按下我的竹子墨水笔的顶部键。我意识到它通过蓝牙连接,当我按下按钮并停止连接时,当我释放它。

我被连接蓝牙设备时运行脚本绊倒了,当我跑

代码语言:javascript
复制
udevadm monitor --environment --udev --kernel --property

然后按一次按钮,得到以下输出:

代码语言:javascript
复制
KERNEL[5118.647193] add      /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/bluetooth/hci0/hci0:3585 (bluetooth)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/bluetooth/hci0/hci0:3585
SUBSYSTEM=bluetooth
DEVTYPE=link
SEQNUM=4094

UDEV  [5118.657098] add      /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/bluetooth/hci0/hci0:3585 (bluetooth)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/bluetooth/hci0/hci0:3585
SUBSYSTEM=bluetooth
DEVTYPE=link
SEQNUM=4094
USEC_INITIALIZED=5118654305
SYSTEMD_ALIAS=/sys/subsystem/bluetooth/devices/hci0:3585
SYSTEMD_WANTS=bluetooth.target
SYSTEMD_USER_WANTS=bluetooth.target
TAGS=:systemd:

KERNEL[5119.311809] remove   /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/bluetooth/hci0/hci0:3585 (bluetooth)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/bluetooth/hci0/hci0:3585
SUBSYSTEM=bluetooth
DEVTYPE=link
SEQNUM=4095

UDEV  [5119.317304] remove   /devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/bluetooth/hci0/hci0:3585 (bluetooth)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/bluetooth/hci0/hci0:3585
SUBSYSTEM=bluetooth
DEVTYPE=link
SEQNUM=4095
USEC_INITIALIZED=5118654305
SYSTEMD_ALIAS=/sys/subsystem/bluetooth/devices/hci0:3585
SYSTEMD_WANTS=bluetooth.target
SYSTEMD_USER_WANTS=bluetooth.target
TAGS=:systemd:

不幸的是,没有idVendor或idProduct。

当我跑的时候

代码语言:javascript
复制
sudo tail -f /var/log/syslog

但是,它会抱怨该文件不存在。

到目前为止,我的udev rules看起来是这样的。

代码语言:javascript
复制
# Run a program when my Bamboo Ink is connected
ACTION=="add" , SUBSYSTEM=="bluetooth", ATTR{idVendor}=="xxx", ATTR{idProduct}=="yyy", ATTRS{model}=="Bamboo Ink", RUN+="xournalpp"

猜测模型是“竹墨”,因为我在journalctl -b中找到了这一行

Feb 26 14:57:35 X380-Yoga kernel: wacom 0005:056A:035F.000C: Unknown device_type for 'Bamboo Ink'. Ignoring.

所以我需要找到idVendor,idProduct和模型。还有别的办法吗?

EN

回答 1

Unix & Linux用户

发布于 2020-06-19 15:07:57

我就是这样做的:

代码语言:javascript
复制
ACTION=="add" , SUBSYSTEM=="bluetooth", DEVPATH=="/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:3585", RUN+="/home/gvb/bin/run-pen-state.sh"

我想做的是在钢笔和橡皮擦之间切换,在Xournal中切换。所需的两个脚本如下所示。他们需要两个小的工具: wmctrl和xdotool..。

"run-pen-state.sh“的内容是

代码语言:javascript
复制
#!/bin/csh
sudo -u gvb -i /home/gvb/bin/pen-state

而“笔式”本身

代码语言:javascript
复制
#!/usr/bin/perl -w

$home=$ENV{'HOME'};
$store=`grep "#state: " ~/bin/pen-state | grep -v store`;
chomp($store);

$command=`export DISPLAY=:0; export XAUTHORITY=$home/.Xauthority; wmctrl -l`;
foreach $line (split(/\n/,$command)){
  if (($line=~ /Xournal/)&&($line=~ /$filename/)){
    $winid=(split(/ /,$line))[0];
  }
}


if($winid){
  system("export DISPLAY=:0; export XAUTHORITY=$home/.Xauthority; wmctrl -i -a $winid");


  if($store =~ /pen/){
    $now="state: eraser";
    system("export DISPLAY=:0; export XAUTHORITY=$home/.Xauthority; xdotool key shift+ctrl+e");
  }else{
    $now="state: pen";
    system("export DISPLAY=:0; export XAUTHORITY=$home/.Xauthority; xdotool key shift+ctrl+p");
  }

  $now="#$now";

  print "$store\n";
  print "$now\n";

  open(SELF,"$home/bin/pen-state");
  read(SELF,$self,-s "$home/bin/pen-state",0);
  close(SELF);
  $self=~ s/$store/$now/;
  open(SELF,">$home/bin/pen-state");
  print SELF $self;
  close(SELF);
}

#state: pen
票数 2
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/569814

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档