forked from mathportillo/wayland-mouse-mapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmousemapper.sh
executable file
·58 lines (47 loc) · 1.24 KB
/
mousemapper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
event_type=EV_KEY
action_type=POINTER_BUTTON
pressed="pressed,"
readarray -t devices <<<$(libinput list-devices | grep pointer -B4 | grep -o '/dev/input/event[0-9]*')
# COMMANDS MAP
BTN_EXTRA=(KEY_LEFTMETA KEY_PAGEUP)
BTN_SIDE=(KEY_LEFTMETA KEY_PAGEDOWN)
function pressKey(){
device=$1; key=$2; value=$3
echo "pressing ${key} ${value}"
evemu-event /dev/input/${device} --sync --type ${event_type} --code ${key} --value ${value};
}
function pressCommand(){
device=$1; button=$2; movement=$3
var=$button[@]
command=${!var}
if [ ${movement} = ${pressed} ]; then
for key in ${command}; do
pressKey ${device} ${key} 1
done
else
for key in ${command}; do
pressKey ${device} ${key} 0
done | tac
fi
}
function parseEventLine(){
device=$1
action=$2
button=$4
movement=$6
# compute only if right action
if [ ${action} = ${action_type} ]; then
pressCommand ${device} ${button} ${movement}
fi
}
function mapDevice(){
device=$1
while read line; do
parseEventLine ${line}
done < <(stdbuf -oL libinput debug-events --device ${device} & )
}
for device in ${devices[@]}; do
( mapDevice ${device} ) &
done
wait