Пример #1
0
static void svgalib_key_close ()
{
	keyboard_setdefaulteventhandler ();
	keyboard_clearstate ();
	keyboard_translatekeys (0);
	keyboard_close ();
}
Пример #2
0
static int _qdgdfv_startup(void)
{
    vga_init();

    _qdgdfv_scale = 1;

    /* only 320x200 supported by now */
    _qdgdfv_screen_x_size = 320;
    _qdgdfv_screen_y_size = 200;

    vga_setmode(G320x200x256);

    _qdgdfv_set_palette();

    keyboard_init();

    keyboard_translatekeys(TRANSLATE_CURSORKEYS);

    _qdgdfv_virtual_screen = (unsigned char *)
        qdgdfv_malloc(_qdgdfv_screen_x_size * _qdgdfv_screen_y_size);

    qdgdfv_clear_virtual_screen();

    /* svgalib runs always fullscreen */
    _qdgdfv_full_screen = 1;

    qdgdfv_logger("qdgdfv_startup", "SVGALIB driver startup");

    return 1;
}
Пример #3
0
static int post_enter_graphics (void)
{
    vga_setmousesupport (1);
    mouse_init("/dev/mouse", vga_getmousetype (), 10);
    if (keyboard_init() != 0) {
	leave_graphics_mode ();
	write_log ("Are you sure you have a keyboard??\n");
	return 0;
    }
    keyboard_seteventhandler (my_kbd_handlerx);
    keyboard_translatekeys (DONT_CATCH_CTRLC);

    mouse_setxrange (-1000, 1000);
    mouse_setyrange (-1000, 1000);
    mouse_setposition (0, 0);

    return 1;
}
int keyboard_init_return_fd(void) {
    char *ptr;

    keyboard_translatekeys(translatemode); /* Honour 'nosigint' setting */

    /* Install default keyboard handler. */
    __svgalib_keyboard_eventhandler = default_handler;

    __svgalib_open_devconsole();
    __svgalib_kbd_fd = __svgalib_tty_fd; /* We are initialized. */

    if (ioctl(__svgalib_kbd_fd, KDGKBMODE, &oldkbmode)) {
	printf("svgalib: cannot get keyboard mode.\n");
	return -1;
    }
    tcgetattr(__svgalib_kbd_fd, &oldkbdtermios);
    newkbdtermios = oldkbdtermios;

    newkbdtermios.c_lflag &= ~(ICANON | ECHO | ISIG);
    newkbdtermios.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
    newkbdtermios.c_cc[VMIN] = 0;	/* Making these 0 seems to have the */
    newkbdtermios.c_cc[VTIME] = 0;	/* desired effect. */

    tcsetattr(__svgalib_kbd_fd, TCSAFLUSH, &newkbdtermios);

    ioctl(__svgalib_kbd_fd, KDSKBMODE, K_MEDIUMRAW);

    keyboard_clearstate();

    __svgalib_read_options(kbd_config_options, kbd_process_option);

    /* Check SVGALIB_KEYMAP env var */
    if ( (ptr = getenv("SVGALIB_KEYMAP")) != 0) {
        kbd_load_keymap(ptr);
    }

    return __svgalib_kbd_fd;		/* OK, return fd. */
}
Пример #5
0
void main(void)
{
    int vgamode, color, leftpressed;
    int x, y;
    vga_init();
    vgamode = vga_getdefaultmode();
    if ((vgamode == -1) || (vga_getmodeinfo(vgamode)->bytesperpixel != 1))
        vgamode = G320x200x256;

    if (!vga_hasmode(vgamode)) {
        printf("Mode not available.\n");
        exit(1);
    }
    printf("\nWARNING: This program will set the keyboard to RAW mode.\n"
           "The keyboard routines in svgalib have not been tested\n"
           "very much. There may be no recovery if something goes\n"
           "wrong.\n\n"
           "Press ctrl-c now to bail out, enter to continue.\n"
           "In the test itself, use 'q' or Escape to quit.\n"
           "It will also terminate after 60 seconds.\n"
           "Use any cursor keys to move, keypad 0 or enter to change color.\n");

    getchar();

    vga_setmode(vgamode);
    gl_setcontextvga(vgamode);
    gl_enableclipping();

    signal(SIGALRM, timeout);

    /* This installs the default handler, which is good enough for most */
    /* purposes. */
    if (keyboard_init()) {
        printf("Could not initialize keyboard.\n");
        exit(1);
    }
    /* Translate to 4 keypad cursor keys, and unify enter key. */
    keyboard_translatekeys(TRANSLATE_CURSORKEYS | TRANSLATE_KEYPADENTER |
                           TRANSLATE_DIAGONAL);
    /* (TRANSLATE_DIAGONAL seems to give problems.) Michael: No doesn't...
       but might not do what you expect.. */

    alarm(60);			/* Terminate after 60 seconds for safety. */

    x = WIDTH / 2;
    y = HEIGHT / 2;
    color = newcolor();
    leftpressed = 0;
    for (;;) {
        /* Draw moving box. */
        gl_fillbox(x, y, 5, 5, color);

        /* Draw key status bar at top of screen. */
        gl_putbox(0, 0, 128, 1, keyboard_getstate());

        /* Wait about 1/100th of a second. */
        /* Note that use of this function makes things less */
        /* smooth because of timer latency. */
        usleep(10000);

        keyboard_update();

        /* Move. */
        if (keyboard_keypressed(SCANCODE_CURSORLEFT))
            x--;
        if (keyboard_keypressed(SCANCODE_CURSORRIGHT))
            x++;
        if (keyboard_keypressed(SCANCODE_CURSORUP))
            y--;
        if (keyboard_keypressed(SCANCODE_CURSORDOWN))
            y++;

        /* Boundary checks. */
        if (x < 0)
            x = 0;
        if (x >= WIDTH)
            x = WIDTH - 1;
        if (y < 1)
            y = 1;
        if (y >= HEIGHT)
            y = HEIGHT - 1;

        /* Check for color change. */
        if (keyboard_keypressed(SCANCODE_KEYPAD0) ||
                keyboard_keypressed(SCANCODE_ENTER)) {
            if (!leftpressed) {
                color = newcolor();
                leftpressed = 1;
            }
        } else
            leftpressed = 0;

        if (keyboard_keypressed(SCANCODE_Q) ||
                keyboard_keypressed(SCANCODE_ESCAPE))
            break;
    }

    keyboard_close();		/* Don't forget this! */
    vga_setmode(TEXT);
    exit(0);
}
Пример #6
0
void KBD_Init(Key_Event_fp_t fp)
{
	int i;

	Key_Event_fp = fp;

	for (i=0 ; i<128 ; i++)
		scantokey[i] = ' ';

	scantokey[  1] = K_ESCAPE;
	scantokey[  2] = '1';
	scantokey[  3] = '2';
	scantokey[  4] = '3';
	scantokey[  5] = '4';
	scantokey[  6] = '5';
	scantokey[  7] = '6';
	scantokey[  8] = '7';
	scantokey[  9] = '8';
	scantokey[ 10] = '9';
	scantokey[ 11] = '0';
	scantokey[ 12] = '-';
	scantokey[ 13] = '=';
	scantokey[ 14] = K_BACKSPACE;
	scantokey[ 15] = K_TAB;
	scantokey[ 16] = 'q';       
	scantokey[ 17] = 'w';       
	scantokey[ 18] = 'e';       
	scantokey[ 19] = 'r';       
	scantokey[ 20] = 't';       
	scantokey[ 21] = 'y';       
	scantokey[ 22] = 'u';       
	scantokey[ 23] = 'i';       
	scantokey[ 24] = 'o';       
	scantokey[ 25] = 'p';       
	scantokey[ 26] = '[';
	scantokey[ 27] = ']';
	scantokey[ 28] = K_ENTER;
	scantokey[ 29] = K_CTRL; //left
	scantokey[ 30] = 'a';
	scantokey[ 31] = 's';       
	scantokey[ 32] = 'd';       
	scantokey[ 33] = 'f';       
	scantokey[ 34] = 'g';       
	scantokey[ 35] = 'h';       
	scantokey[ 36] = 'j';       
	scantokey[ 37] = 'k';       
	scantokey[ 38] = 'l';       
	scantokey[ 39] = ';';
	scantokey[ 40] = '\'';
	scantokey[ 41] = '`';
	scantokey[ 42] = K_SHIFT; //left
	scantokey[ 43] = '\\';
	scantokey[ 44] = 'z';       
	scantokey[ 45] = 'x';  
	scantokey[ 46] = 'c';
	scantokey[ 47] = 'v';       
	scantokey[ 48] = 'b';
	scantokey[ 49] = 'n';       
	scantokey[ 50] = 'm';       
	scantokey[ 51] = ',';
	scantokey[ 52] = '.';
	scantokey[ 53] = '/';
	scantokey[ 54] = K_SHIFT; //right
	scantokey[ 55] = '*'; //keypad
	scantokey[ 56] = K_ALT; //left
	scantokey[ 57] = ' ';
	// 58 caps lock
	scantokey[ 59] = K_F1;
	scantokey[ 60] = K_F2;
	scantokey[ 61] = K_F3;
	scantokey[ 62] = K_F4;
	scantokey[ 63] = K_F5;
	scantokey[ 64] = K_F6;
	scantokey[ 65] = K_F7;
	scantokey[ 66] = K_F8;
	scantokey[ 67] = K_F9;
	scantokey[ 68] = K_F10;
	// 69 numlock
	// 70 scrollock
	scantokey[ 71] = K_KP_HOME;
	scantokey[ 72] = K_KP_UPARROW;
	scantokey[ 73] = K_KP_PGUP;
	scantokey[ 74] = K_KP_MINUS;
	scantokey[ 75] = K_KP_LEFTARROW;
	scantokey[ 76] = K_KP_5;
	scantokey[ 77] = K_KP_RIGHTARROW;
	scantokey[ 79] = K_KP_END;
	scantokey[ 78] = K_KP_PLUS;
	scantokey[ 80] = K_KP_DOWNARROW;
	scantokey[ 81] = K_KP_PGDN;
	scantokey[ 82] = K_KP_INS;
	scantokey[ 83] = K_KP_DEL;
	// 84 to 86 not used
	scantokey[ 87] = K_F11;
	scantokey[ 88] = K_F12;
	// 89 to 95 not used
	scantokey[ 96] = K_KP_ENTER; //keypad enter
	scantokey[ 97] = K_CTRL; //right
	scantokey[ 98] = K_KP_SLASH;
	scantokey[ 99] = K_F12; // print screen, bind to screenshot by default
	scantokey[100] = K_ALT; // right

	scantokey[101] = K_PAUSE; // break
	scantokey[102] = K_HOME;
	scantokey[103] = K_UPARROW;
	scantokey[104] = K_PGUP;
	scantokey[105] = K_LEFTARROW;
	scantokey[106] = K_RIGHTARROW;
	scantokey[107] = K_END;
	scantokey[108] = K_DOWNARROW;
	scantokey[109] = K_PGDN;
	scantokey[110] = K_INS;
	scantokey[111] = K_DEL;

	scantokey[119] = K_PAUSE;

	if (keyboard_init())
		Sys_Error("keyboard_init() failed");
	keyboard_seteventhandler(keyhandler);
	keyboard_translatekeys(DONT_CATCH_CTRLC);
}