Files
michaelschiemer/scripts/test/test_arrow_keys.php
Michael Schiemer 887847dde6 refactor: reorganize project structure for better maintainability
- Move 45 debug/test files from root to organized scripts/ directories
- Secure public/ directory by removing debug files (security improvement)
- Create structured scripts organization:
  • scripts/debug/      (20 files) - Framework debugging tools
  • scripts/test/       (18 files) - Test and validation scripts
  • scripts/maintenance/ (5 files) - Maintenance utilities
  • scripts/dev/         (2 files) - Development tools

Security improvements:
- Removed all debug/test files from public/ directory
- Only production files remain: index.php, health.php

Root directory cleanup:
- Reduced from 47 to 2 PHP files in root
- Only essential production files: console.php, worker.php

This improves:
 Security (no debug code in public/)
 Organization (clear separation of concerns)
 Maintainability (easy to find and manage scripts)
 Professional structure (clean root directory)
2025-10-05 10:59:15 +02:00

95 lines
2.3 KiB
PHP

<?php
require_once __DIR__ . '/vendor/autoload.php';
echo "Arrow Key Test\n";
echo "==============\n\n";
echo "Press arrow keys to test input reading.\n";
echo "Press 'q' to quit.\n\n";
// Enable raw mode
shell_exec('stty -icanon -echo');
function readKey(): string
{
$key = fgetc(STDIN);
if ($key === false) {
return '';
}
// Handle escape sequences (arrow keys, etc.)
if ($key === "\033") {
$sequence = $key;
// Read the next character
$next = fgetc(STDIN);
if ($next === false) {
return $key; // Just escape
}
$sequence .= $next;
// If it's a bracket, read more
if ($next === '[') {
$third = fgetc(STDIN);
if ($third !== false) {
$sequence .= $third;
// Some sequences have more characters (like Page Up/Down)
if ($third === '5' || $third === '6' || $third === '3') {
$fourth = fgetc(STDIN);
if ($fourth !== false) {
$sequence .= $fourth;
}
}
}
}
return $sequence;
}
return $key;
}
try {
while (true) {
$key = readKey();
if ($key === 'q') {
break;
}
$hexKey = bin2hex($key);
echo "Key pressed: '$key' (hex: $hexKey)\n";
switch ($key) {
case "\033[A":
echo " -> Arrow UP detected!\n";
break;
case "\033[B":
echo " -> Arrow DOWN detected!\n";
break;
case "\033[C":
echo " -> Arrow RIGHT detected!\n";
break;
case "\033[D":
echo " -> Arrow LEFT detected!\n";
break;
case "\n":
echo " -> ENTER detected!\n";
break;
case " ":
echo " -> SPACE detected!\n";
break;
case "\033":
echo " -> ESC detected!\n";
break;
default:
echo " -> Regular key: '$key'\n";
break;
}
}
} finally {
// Restore terminal
shell_exec('stty icanon echo');
echo "\nTerminal restored. Goodbye!\n";
}