Bamboo Ink 펜의 위쪽 버튼을 누를 때 어떻게 명령을 실행하나요?

Bamboo Ink 펜의 위쪽 버튼을 누를 때 어떻게 명령을 실행하나요?

Bamboo Ink Pen의 위쪽 키를 누르면 명령을 실행하려고 했습니다. 버튼을 눌렀을 때 연결이 멈췄다가 버튼을 놓았을 때 블루투스를 통해 연결되었다는 것을 깨달았습니다.

나는 넘어졌다Bluetooth 장치가 연결되면 스크립트 실행내가 달릴 때

udevadm monitor --environment --udev --kernel --property

버튼을 한 번 누르면 다음과 같은 결과가 출력됩니다.

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가 없습니다.

내가 달릴 때

sudo tail -f /var/log/syslog

그런데 파일이 없다고 뜹니다.

udev rules지금까지의 내 모습은 이렇습니다.

# 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, model을 찾아야 합니다. 다른 방법이 있나요?

답변1

이것이 내가 하는 방법이다:

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"의 내용은 다음과 같습니다.

#!/bin/csh
sudo -u gvb -i /home/gvb/bin/pen-state

그리고 "펜 상태"자체가

#!/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

2022년 2월 업데이트됨:
방금 Ubuntu 22.04, Kernel 5.16.8 및 Gnome 41.3에서는 즉시 작동한다는 것을 알았습니다. 상단 버튼은 Super+ AudioMicMute조합으로 감지되며 이를 사용하여 Gnome 설정에서 단축키를 할당할 수 있습니다. 하지만 언제 작업이 시작될지는 알 수 없습니다.

원래 답변:
내 접근 방식은 Guillaume의 이전 답변과 거의 동일합니다. 그러나 그의 대답에 대한 문제는 어떤 장치가 블루투스 하위 시스템의 추가 작업을 트리거했는지 구별하는 방법을 찾을 수 없다는 것입니다. 따라서 블루투스를 통해 다른 장치를 연결할 때 Guillaume의 간단한 규칙도 일치합니다. 하지만 Lenovo Active Pen 2를 사용하면서 상단 버튼을 누를 때마다 두 가지 중 하나의 현상이 발생한다는 사실을 발견했습니다.

사례 1) 펜이 1~2초 내에 연결되고 연결이 끊어집니다. udevadm monitor추가 및 삭제 작업만 표시됩니다.

사례 2) udev 추가 작업 후 펜 이름이 HID로 인식됩니다.Lenovo 액티브 펜2 키보드. 그런 다음 제거하는 데 약 10 초가 걸립니다.

ACTION=="add", SUBSYSTEM=="bluetooth", DEVPATH=="/devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/bluetooth/hci0/hci0:3585", RUN+="/usr/local/bin/bluetooth_event_detected.sh add"
ACTION=="remove", SUBSYSTEM=="bluetooth", DEVPATH=="/devices/pci0000:00/0000:00:14.0/usb1/1-7/1-7:1.0/bluetooth/hci0/hci0:3585", RUN+="/usr/local/bin/bluetooth_event_detected.sh remove"
ACTION=="add", SUBSYSTEM=="hid", DEVPATH=="/devices/virtual/misc/uhid/0005:17EF:60A8.*", RUN+="/usr/local/bin/bluetooth_event_detected.sh force"

그래서 추가 이벤트와 다음 제거 이벤트 사이에 필요한 시간을 계산하는 스크립트를 트리거하는 udev 규칙에서 추가 및 제거 작업을 모니터링합니다. 2초 미만이면 펜이라고 가정하고 아래에 플래그를 설정합니다 /tmp/stylus. 펜이 HID로 인식되는 경우에도 같은 현상이 발생합니다.

#!/bin/bash
# PATH is not provided in an udev environment
PATH=/bin:/usr/bin:/usr/local/bin

DIRECTORY=/tmp/stylus
TSFILE=$DIRECTORY/bluetooth_timestamp
BTN_PRESSED_FLAG=$DIRECTORY/stylus_button_pressed
TIME_DELTA="2"  

ACTION=$1
NOW=$(date +%s)


mkdir -p $DIRECTORY 
chmod 777 $DIRECTORY

if [ "$ACTION" = "add" ]; then
        echo $NOW > $TSFILE                   
elif [ "$ACTION" = "remove" ]; then
        ADDED_TS=$(cat $TSFILE)
        DIFF=$(($NOW-$ADDED_TS))
        echo diff: $DIFF
        # if the time between adding and removing is 
        # 2 seconds or less, we assume the stylus button
        # was pressed
        if [ "$DIFF" -le "$TIME_DELTA" ]; then
                touch $BTN_PRESSED_FLAG          
                chmod 666 $BTN_PRESSED_FLAG 
        fi
elif [ "$ACTION" = "force" ]; then
        touch $BTN_PRESSED_FLAG
        chmod 666 $BTN_PRESSED_FLAG
fi    

마지막으로 데스크톱 환경에 로그인하면 자동으로 시작되어 지속적 /tmp/stylus으로 gnome-screenshot -i.

#!/bin/bash

FILE=/tmp/stylus/stylus_button_pressed
CMD="gnome-screenshot -i"

while true; do
        if [ -f $FILE ]; then
                echo running command
                $CMD
                rm $FILE
        fi
        sleep 0.1
done

우아하지는 않지만 작동합니다.

관련 정보