Last active
September 7, 2023 01:49
-
-
Save terremoth/ddf439f37230d41ec2c047fca58fe1c1 to your computer and use it in GitHub Desktop.
key.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//echo "\033[23\033[;H"; | |
function is_little_endian() { | |
$testint = 0x00FF; | |
$p = pack('S', $testint); | |
return $testint === current(unpack('v', $p)); | |
} | |
function to_little_endian(string $input) : string { | |
if (!is_little_endian()) { | |
return $input; | |
} | |
return implode(array_reverse(str_split($input,2))); | |
} | |
$buffer_size = 144; | |
$buffer_part = 48; | |
while(true) { | |
//3a54f36400000000aeca050000000000040004001e000000 | |
$event = @fopen("/dev/input/event4", "rb"); | |
if ($event) { | |
while (($buffer = fread($event, $buffer_size)) !== false) { | |
system("clear"); | |
//echo substr($buffer, 0,8).PHP_EOL; | |
$hex = bin2hex($buffer); | |
$start = 0; | |
//echo $hex.PHP_EOL; | |
while($start < $buffer_size*2) { | |
$buffer_hex = substr($hex, $start, $buffer_part); | |
echo $buffer_hex.PHP_EOL; | |
$seconds = substr($buffer_hex,0,8); | |
$seconds = hexdec(to_little_endian($seconds)); | |
$microseconds = substr($buffer_hex, 8,16); | |
$microseconds = hexdec(to_little_endian($microseconds)); | |
// 2 bytes = 4hex chars | |
$type = substr($buffer_hex, 16, 4); | |
$type = hexdec(to_little_endian($type)); | |
echo $type.PHP_EOL; | |
$code = 1; // 2 bytes = 4hex | |
$value = 2; // 4 bytes = 8hex chars | |
//echo $seconds.' - '.$microseconds.' | time: '.time().' microtime: '.microtime().PHP_EOL; | |
$start += $buffer_part; | |
} | |
//$timeFull = substr($hex,0, 16); | |
//$sec = hexdec(substr($timeFull,0,8)); | |
//$microsec = substr($timeFull,8,16); | |
//echo $sec.' - '.$microsec.PHP_EOL; | |
//echo strlen($buffer); | |
//echo "|"; | |
//var_dump($hex).PHP_EOL; | |
//var_dump($buffer).PHP_EOL; | |
//echo $hex.PHP_EOL; | |
} | |
if (!feof($event)) { | |
echo "EOF".PHP_EOL; | |
} | |
echo "Closing handle"; | |
fclose($event); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment