Skip to content

Instantly share code, notes, and snippets.

@flatcap
Created May 30, 2022 10:33
Show Gist options
  • Save flatcap/0306116f7c8d103873e5b57014987a78 to your computer and use it in GitHub Desktop.
Save flatcap/0306116f7c8d103873e5b57014987a78 to your computer and use it in GitHub Desktop.
mouse php dump events
#!/usr/bin/php
<?php
system("stty -icanon"); // Enable shell input
system("stty -echo"); // Disable characters printing
echo "\e[?1003h\e[?1015h\e[?1006h"; // Mouse trap all, urxvt, SGR1006
function shutdown(){ // Cleaning before quiting
echo "\e[?1000l"; // Disable mouse trap
system("stty echo"); // Enable back characters printing
exit; // Cleaned, quit
}
register_shutdown_function("shutdown"); // Handle regular END of script
declare(ticks = 1); // Allow posix signal handling
pcntl_signal(SIGINT,"shutdown"); // Catch SIGINT (CTRL+C)
$KEY = "";
while ($KEY = fread(STDIN,16)) {
$e = explode(";",explode("<",$KEY)[1]);
if ($e[0] === "0" && substr($e[2],-1) === "M"){
echo "BUTTON DOWN, LINE ".substr($e[2],0,-1)." COLUMN ".$e[1]."\n";
}
if ($e[0] === "0" && substr($e[2],-1) === "m"){
echo "BUTTON UP, LINE ".substr($e[2],0,-1)." COLUMN ".$e[1]."\n";
}
if ($e[0] === "64"){
echo "WHEEL SCROLL UP, LINE ".substr($e[2],0,-1)." COLUMN ".$e[1]."\n";
}
if ($e[0] === "65"){
echo "WHEEL SCROLL DOWN, LINE ".substr($e[2],0,-1)." COLUMN ".$e[1]."\n";
}
if ($e[0] === "1" && substr($e[2],-1) === "M"){
echo "WHEEL BUTTON DOWN, LINE ".substr($e[2],0,-1)." COLUMN ".$e[1]."\n";
}
if ($e[0] === "1" && substr($e[2],-1) === "m"){
echo "WHEEL BUTTON UP, LINE ".substr($e[2],0,-1)." COLUMN ".$e[1]."\n";
}
if ($e[0] === "35"){
echo "MOUSE MOVE, LINE ".substr($e[2],0,-1)." COLUMN ".$e[1]."\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment