Skip to content

Instantly share code, notes, and snippets.

@webdev23
Created March 27, 2018 23:01
Show Gist options
  • Save webdev23/4c6ba420df321729aa5dc11e821f3b40 to your computer and use it in GitHub Desktop.
Save webdev23/4c6ba420df321729aa5dc11e821f3b40 to your computer and use it in GitHub Desktop.
Realtime keystrokes in php bash scripts
#!/usr/bin/php
<?php
$trap = [];
system("xinput list | grep -Po 'id=\K\d+(?=.*slave\s*keyboard)' \
| xargs -P0 -n1 xinput test > keys &");
while (true){
$data = file("keys");
$key = $data;
array_push($trap,$key);
if ((@strpos(implode($trap[count($trap)-1]), 'press 36') !== false)){
echo "[+] return!";
$trap = [];
file_put_contents("keys", "");
}
if ((@strpos(implode($trap[count($trap)-1]), 'press 37') !== false)){
echo "\n[+] left ctrl!";
$trap = [];
file_put_contents("keys", "");
}
usleep(10000); /* <- CAUTION */
}
//🜛 keycodes list:
//🜛 xmodmap -pke | less
@webdev23
Copy link
Author

This base script will detect RETURN and LEFT CTRL keys press from php.
Can be adapted for any keys.
Require linux tools, any x env.
NO ROOT
It listen for keystrokes globally, the focus can be outside the shell window

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment