2
* mouse libcaca mouse events
3
* Copyright (c) 2006-2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
6
* This program is free software. It comes without any warranty, to
7
* the extent permitted by applicable law. You can redistribute it
8
* and/or modify it under the terms of the Do What The Fuck You Want
9
* To Public License, Version 2, as published by Sam Hocevar. See
10
* http://sam.zoy.org/wtfpl/COPYING for more details.
14
#if !defined(__KERNEL__)
23
int main(int argc, char *argv[])
26
int x = 0, y = 0, p = 0, b = 0;
30
cv = caca_create_canvas(80, 24);
33
printf("Failed to create canvas\n");
37
dp = caca_create_display(cv);
40
printf("Failed to create display\n");
44
caca_set_display_time(dp, 40000);
45
caca_set_cursor(dp, 0);
50
while (caca_get_event(dp, CACA_EVENT_ANY, &ev, 0))
52
if ((caca_get_event_type(&ev) & CACA_EVENT_KEY_PRESS))
56
if (caca_get_event_type(&ev) & CACA_EVENT_MOUSE_MOTION)
58
x = caca_get_event_mouse_x(&ev);
59
y = caca_get_event_mouse_y(&ev);
61
if (caca_get_event_type(&ev) & CACA_EVENT_MOUSE_PRESS)
64
b = caca_get_event_mouse_button(&ev);
66
else if (caca_get_event_type(&ev) & CACA_EVENT_MOUSE_RELEASE)
69
b = caca_get_event_mouse_button(&ev);
72
caca_printf(cv, 0, 0, "%d,%d", x, y);
75
caca_printf(cv, 0, 1, "Mouse button %d %s", b,
76
p == 1 ? "pressed" : "released");
79
caca_printf(cv, x - 2, y - 1, " |");
80
caca_printf(cv, x - 2, y, "--|--");
81
caca_printf(cv, x - 2, y + 1, " |");
82
caca_refresh_display(dp);
83
caca_clear_canvas(cv);
86
caca_free_display(dp);