// Test event watching functionality
use('input');

// Start watching events
input.watch($_);

$_.receiver(msg => {
  if (msg.type) {
    log.console("Received event:", msg.type);
    
    // Log specific event details
    switch(msg.type) {
      case "key_down":
      case "key_up":
        log.console("  Key:", msg.key, "Scancode:", msg.scancode, "Down:", msg.down);
        break;
      case "mouse_motion":
        log.console("  Mouse position:", msg.pos, "Delta:", msg.d_pos);
        break;
      case "mouse_button_down":
      case "mouse_button_up":
        log.console("  Button:", msg.button, "Position:", msg.mouse, "Down:", msg.down);
        break;
    }
    
    // Stop watching after receiving 10 events
    if (!$_.event_count) $_.event_count = 0;
    $_.event_count++;
    
    if ($_.event_count >= 10) {
      log.console("Received 10 events, stopping watch");
      input.unwatch($_);
    }
  }
});

log.console("Event watcher started. Press keys or move mouse to generate events.");
log.console("Will stop after 10 events.");