I want to continually track the mouse as it moves, or at least every 0.5 seconds:
require "curses"
include Curses
init_screen
start_color
init_pair(COLOR_BLUE,COLOR_BLUE,COLOR_WHITE)
init_pair(COLOR_RED,COLOR_RED,COLOR_WHITE)
crmode
noecho
stdscr.keypad(true)
close = false
begin
mousemask(BUTTON1_CLICKED|BUTTON2_CLICKED|BUTTON3_CLICKED|BUTTON4_CLICKED)
count = 0
while( count < 10 )
sleep 0.5
m = getmouse
winx = Window.new(7,30,10,10)
winx.keypad = true
winx.box(?|, ?-, ?+)
winx.setpos(2,3)
winx.addstr "Loop Count: " + count.to_s
winx.setpos(3,3)
winx.addstr "Mouse Position: " + m.inspect
winx.refresh
count += 1
end
refresh
ensure
close_screen
end
I think I'm close, but for some reason, getmouse is returning nill? Why is this? Does getmouse only work after an event such as a click? If so, is it impossible to continually track the mouse?
This from the ruby documentation
getmouse() click to toggle source
Returns coordinates of the mouse.
This will read and pop the mouse event data off the queue
See the BUTTON*, ALL_MOUSE_EVENTS and REPORT_MOUSE_POSITION constants
REPORT_MOUSE_POSITION
appears to be key here, but I really don't know how to use these constants. getmouse(REPORT_MOUSE_POSITION)
doesn't work..sorry if that's majorly nooby, but there isn't much documentation out there.