/*
          __
         / /_______________  ____  ___
        / __/ ___/ ___/ __ \/ __ \/ _ \
       / /_(__  ) /__/ /_/ / /_/ /  __/
       \__/____/\___/\____/ .___/\___/
                         /_/

    testkeyboard.c
*/

#include <tscope.h>
#include <tscope/internal.h>

int main()
{
    // initialize the screen
    ts_debug(DEBUG0);
    ts_scrsize(SIZE2);
    ts_init();

    // define the response keys
    int i;
    for (i = KEY_A; i <= KEY_CAPSLOCK; i++)
        ts_defkey(i);
    int mouse = ts_defkey(M1);

    // some instructions
    ts_printf(-XMAX + 20, YMAX - 40, "testkeyboard.c");
    ts_printf(-XMAX + 20, YMAX - 50,
              "When a keypress is detected the corresponding code will be highlighted");
    ts_printf(-XMAX + 20, YMAX - 60,
              "Press the left mouse button to exit");

    // draw the button array
    int x = 0, y = 0;
    for (i = KEY_A; i <= KEY_CAPSLOCK; i++) {
        ts_printf(-XMAX + 20 + x, YMAX - 80 - y, "%s", _sdefkey[i]);
        y += 20;
        if (y > 480) {
            y = 0;
            x += 120;
        }
    }

    // update the button array
    int r;
    do {
        r = ts_respstatus();
        if (r) {
            for (i = KEY_A; i <= KEY_CAPSLOCK; i++)
                if (i == r) {
                    ts_fgcolor(RED);
                    x = (r - 1) / 25 * 120;
                    y = ((r - 1) % 25) * 20;
                    ts_printf(-XMAX + 20 + x, YMAX - 80 - y, "%s",
                              _sdefkey[r]);
                    ts_wait(mtt(1000));
                    ts_fgcolor(WHITE);
                    ts_printf(-XMAX + 20 + x, YMAX - 80 - y, "%s",
                              _sdefkey[r]);
                }
        }
    } while (r != mouse);

    // exit
    return 0;
}

END_OF_MAIN();


top
Persoonlijke pagina Universiteit GentTscope
Allegro | Cygwin | Gcc
© See license.html for copyright information