Skip to content

Instantly share code, notes, and snippets.

@haydenflinner
Created September 24, 2025 15:05
Show Gist options
  • Select an option

  • Save haydenflinner/daa58868272c896f6497414d2c0b0547 to your computer and use it in GitHub Desktop.

Select an option

Save haydenflinner/daa58868272c896f6497414d2c0b0547 to your computer and use it in GitHub Desktop.
Nushell script demonstrating mouse handler.
# Mouse event handler with escape option
while true {
let event = input listen
# Check for keyboard input to exit
if $event.type == "key" {
if $event.code == "Esc" {
print "Exiting on Escape key..."
break
} else {
print $"Exiting on key press: ($event.code)"
break
}
}
# Handle mouse events
if $event.type == "mouse" {
match $event.kind {
"Left_down" => { print $"Left click at ($event.col), ($event.row)" }
"Right_down" => { print $"Right click at ($event.col), ($event.row)" }
"moved" => { print $"Mouse moved to ($event.col), ($event.row)" }
}
}
}
@haydenflinner
Copy link
Author

It seems that moved events are throttled to only one somehow. And the coordinates are those of the window itself, not the per-program space. So would likely need to take over the screen contents to make use of this, maybe with alt-screen. Columnar/x coords work fine though, it's only vertically that things change as you print.

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