gpt4 book ai didi

linux - 将带有时间戳的鼠标坐标和鼠标点击写入文件?

转载 作者:太空宇宙 更新时间:2023-11-04 10:01:25 25 4
gpt4 key购买 nike

我正在尝试创建一个每 5 毫秒记录一次鼠标位置的 bash 脚本。我还想记录鼠标点击的时间戳和位置。

使用 xdotool getmouselocation 可以轻松记录鼠标位置。我已经能够使用此处的一些建议来记录鼠标点击:https://unix.stackexchange.com/questions/106736/detect-if-mouse-button-is-pressed-then-invoke-a-script-or-command但是,我无法将两者结合起来。

有什么办法可以实现吗?提前致谢!

最佳答案

https://unix.stackexchange.com/questions/106736/detect-if-mouse-button-is-pressed-then-invoke-a-script-or-command 的已接受答案中有一个例子来改变鼠标状态。只需稍加修改,您就可以在按下鼠标按钮时打印鼠标位置。

@Gem Taylor 提到为此使用脚本语言不是一种可选方式。

在测试运行期间,我遇到了无法捕获点击的情况。

#!/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\['"."'\]=down' | sort)
while true; do
sleep 0.005
STATE2=$(xinput --query-state $MOUSE_ID | grep 'button\['"."'\]=down' | sort)
CLICK=$(comm -13 <(echo "$STATE1") <(echo "$STATE2"))
if [[ -n $CLICK ]]; then
echo "$CLICK"
xinput --query-state $MOUSE_ID | grep 'valuator\['
fi
STATE1=$STATE2
done

关于linux - 将带有时间戳的鼠标坐标和鼠标点击写入文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55922664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com