Pastey mouse.ex
- Posted by jimcbrown
(admin)
Dec 01, 2014
----------------
-- mouse test --
----------------
-- This is a very simple program to demonstrate the get_mouse() built-in
-- function. No call is made to mouse_events(), so by default all events are
-- reported by get_mouse().
include mouse.e
include graphics.e
constant MAX_LINE = 8
constant IS_LINUX = platform()=LINUX
clear_screen()
puts(1, "\t\t\tPress q to Quit\n")
procedure try_mouse()
integer color, line, eventNo, c, action
object event
sequence movement, str
color = 14
eventNo = 0
line = MAX_LINE
while 1 do
sleep(1) -- do not busy loop the cpu
event = get_mouse()
if sequence(event) then
action = event[1]
eventNo += 1
movement = "- -- -- --"
if IS_LINUX and action = ANY_UP then
movement[4] = 'U'
movement[7] = 'U'
movement[10] = 'U'
else
if (IS_LINUX and action = MOVE) or
((not IS_LINUX) and and_bits(action, MOVE)) then
movement[1] = 'M'
mouse_pointer(0)
mouse_pointer(1)
end if
if and_bits(action, LEFT_DOWN) then
movement[3] = 'D'
color += 1
if color > 15 then
color = 0
end if
end if
if and_bits(action, LEFT_UP) then
movement[4] = 'U'
end if
if and_bits(action, MIDDLE_DOWN) then
movement[6] = 'D'
end if
if and_bits(action, MIDDLE_UP) then
movement[7] = 'U'
end if
if and_bits(action, RIGHT_DOWN) then
movement[9] = 'D'
end if
if and_bits(action, RIGHT_UP) then
movement[10] = 'U'
end if
end if
str = sprintf("event# %4d: action: %d %s, x:%d, y:%d \r",
{eventNo, action, movement, event[2], event[3]})
line += 1
if line > MAX_LINE then
line = 3
end if
position(line, 1)
puts(1, str)
text_color(BRIGHT_MAGENTA)
puts(1, str)
text_color(WHITE)
puts(1, '\n' & repeat(' ', length(str)))
position(line, 1)
end if
c = get_key()
if c != -1 then
if c = 'q' then
exit
end if
position(22, 1)
puts(1, c)
end if
end while
end procedure
try_mouse()