void eof_controller_read_button_names(EOF_CONTROLLER * cp) { int i; eof_log("eof_controller_read_button_names() entered", 1); if(!cp) { return; } for(i = 0; i < EOF_CONTROLLER_MAX_BUTTONS; i++) { switch(cp->button[i].type) { case EOF_CONTROLLER_BUTTON_TYPE_KEY: { (void) ustrcpy(cp->button[i].name, scancode_to_name(cp->button[i].key)); break; } case EOF_CONTROLLER_BUTTON_TYPE_JOYBUTTON: { (void) snprintf(cp->button[i].name, sizeof(cp->button[i].name) - 1, "Joy %d %s", cp->button[i].joy, joy[cp->button[i].joy].button[cp->button[i].key].name); break; } case EOF_CONTROLLER_BUTTON_TYPE_JOYAXIS: { (void) snprintf(cp->button[i].name, sizeof(cp->button[i].name) - 1, "Joy %d %s Axis (%s)", cp->button[i].joy, joy[cp->button[i].joy].stick[cp->button[i].index].axis[cp->button[i].key].name, cp->button[i].d == 0 ? "-" : "+"); break; } } } }
static const char *keycode_getter(int index, int *list_size) { if (index >= 0) { return scancode_to_name(index + 1); } else { *list_size = KEY_MAX - 1; return NULL; } }
/* dialog callback for retrieving information about the accent key */ AL_CONST char *accent_list_getter(int index, int *list_size) { if (index < 0) { if (list_size) *list_size = KEY_MAX; return NULL; } return scancode_to_name(index); }
/* dialog callback for retrieving information about the keymap list */ char *keymap_list_getter(int index, int *list_size) { static char buf[256]; int val; if (index < 0) { if (list_size) *list_size = KEY_MAX; return NULL; } val = editor_table[index]; if (val >= ' ') usprintf(buf, "%-16s -> U+%04X - '%c'", scancode_to_name(index), val, val); else usprintf(buf, "%-16s -> U+%04X - %s", scancode_to_name(index), val, ascii_name[val]); return buf; }
static void test_key_map(void) { int i, k, u; static int key_was_pressed[KEY_MAX + 1] = {0}; static int key_is_pressed[KEY_MAX + 1] = {0}; static char *welcome[] = { "Key that is pressed now is marked with red", "Key that was pressed is marked with yellow", "Press mouse button or Escape to exit test", 0 }; /* Clear screen and output prompt. */ clear_to_color(screen, white); for (i = 0; welcome[i] != 0; i++) textout_ex(screen, font, welcome[i], 8, i * 8 + 8, black, -1); clear_to_color(screen, white); for (i = 0; i < KEY_MAX; i++) textprintf_ex(screen, font, 32 + (i % 4) * 160, 32 + (i / 4) * 14, black, -1, "%s", scancode_to_name (i)); do { poll_keyboard(); poll_mouse(); } while ((key[KEY_ESC]) || (mouse_b)); do { while (keypressed()) { u = ureadkey (&k); textprintf_centre_ex (screen, font, SCREEN_W / 2, 8, red, white, "> %c <", u); } poll_keyboard(); poll_mouse(); for (i = 0; i < KEY_MAX; i++) { if (key[i]) key_was_pressed[i] = key_is_pressed[i] = 1; else key_is_pressed[i] = 0; } for (i = 0; i < KEY_MAX; i++) { int x = 16 + (i % 4) * 160; int y = 32 + (i / 4) * 14; if (key_is_pressed[i]) rectfill(screen, x, y, x + 7, y + 7, red); else if (key_was_pressed[i]) rectfill(screen, x, y, x + 7, y + 7, yellow); else rectfill(screen, x, y, x + 7, y + 7, white); } rest(1); } while ((!key[KEY_ESC]) && (!mouse_b)); do { poll_keyboard(); poll_mouse(); } while ((key[KEY_ESC]) || (mouse_b)); clear_keybuf(); }
/* handle the test command */ int tester() { char buf[256]; int a, i; show_mouse(NULL); acquire_screen(); clear_to_color(screen, palette_color[8]); for (i=0; i<KEY_MAX; i++) textout_ex(screen, font, scancode_to_name(i), 32+(i%4)*160, 60+(i/4)*10, palette_color[255], palette_color[8]); release_screen(); do { poll_keyboard(); poll_mouse(); } while ((key[KEY_ESC]) || (mouse_b)); do { poll_keyboard(); poll_mouse(); acquire_screen(); for (i=0; i<KEY_MAX; i++) textout_ex(screen, font, key[i] ? "*" : " ", 16+(i%4)*160, 60+(i/4)*10, palette_color[255], palette_color[8]); buf[0] = 0; if (key_shifts & KB_SHIFT_FLAG) strcat(buf, "shift "); if (key_shifts & KB_CTRL_FLAG) strcat(buf, "ctrl "); if (key_shifts & KB_ALT_FLAG) strcat(buf, "alt "); if (key_shifts & KB_LWIN_FLAG) strcat(buf, "lwin "); if (key_shifts & KB_RWIN_FLAG) strcat(buf, "rwin "); if (key_shifts & KB_MENU_FLAG) strcat(buf, "menu "); if (key_shifts & KB_COMMAND_FLAG) strcat(buf, "command "); if (key_shifts & KB_SCROLOCK_FLAG) strcat(buf, "scrolock "); if (key_shifts & KB_NUMLOCK_FLAG) strcat(buf, "numlock "); if (key_shifts & KB_CAPSLOCK_FLAG) strcat(buf, "capslock "); if (key_shifts & KB_INALTSEQ_FLAG) strcat(buf, "inaltseq "); if (key_shifts & KB_ACCENT1_FLAG) strcpy(buf, "accent1 "); if (key_shifts & KB_ACCENT2_FLAG) strcpy(buf, "accent2 "); if (key_shifts & KB_ACCENT3_FLAG) strcpy(buf, "accent3 "); if (key_shifts & KB_ACCENT4_FLAG) strcpy(buf, "accent4 "); while (strlen(buf) < 128) strcat(buf, " "); textout_ex(screen, font, buf, 0, 0, palette_color[255], palette_color[8]); release_screen(); if (keypressed()) { a = ureadkey(&i); if (!a) a = ' '; textprintf_ex(screen, font, 32, 34, palette_color[255], palette_color[8], "ureadkey() returns scancode 0x%02X, U+0x%04X, '%c'", i, a, a); } } while ((!key[KEY_ESC]) && (!mouse_b)); do { poll_keyboard(); poll_mouse(); } while ((key[KEY_ESC]) || (mouse_b)); clear_keybuf(); show_mouse(screen); return D_REDRAW; }
int eof_controller_set_button(EOF_CONTROLLER_BUTTON * bp) { int i, j, k; int count = 0; char ignore[4][8][2]; char ignoreb[4][32]; memset(ignore, 0, sizeof(ignore)); memset(ignoreb, 0, sizeof(ignoreb)); eof_log("eof_controller_set_button() entered", 1); if(!bp) { return 0; } while(!key[KEY_ESC]) { /* scan keyboard keys first */ for(i = 0; i < KEY_MAX; i++) { if((i != KEY_SPACE) && key[i]) { bp->type = EOF_CONTROLLER_BUTTON_TYPE_KEY; bp->key = i; (void) ustrcpy(bp->name, scancode_to_name(i)); return 1; } } /* scan joysticks */ (void) poll_joystick(); for(i = 0; i < num_joysticks; i++) { /* scan buttons */ for(j = 0; j < joy[i].num_buttons; j++) { if(joy[i].button[j].b) { if(count == 0) { ignoreb[i][j] = 1; } else if(!ignoreb[i][j]) { bp->type = EOF_CONTROLLER_BUTTON_TYPE_JOYBUTTON; bp->joy = i; bp->key = j; (void) snprintf(bp->name, sizeof(bp->name) - 1, "Joy %d %s", i, joy[i].button[j].name); return 1; } } else { ignoreb[i][j] = 0; } } /* scan sticks */ for(j = 0; j < joy[i].num_sticks; j++) { for(k = 0; k < joy[i].stick[j].num_axis; k++) { if(joy[i].stick[j].axis[k].d1) { if(count == 0) { ignore[i][j][k] = 1; } else if(!ignore[i][j][k]) { bp->type = EOF_CONTROLLER_BUTTON_TYPE_JOYAXIS; bp->joy = i; bp->index = j; bp->key = k; bp->d = 0; (void) snprintf(bp->name, sizeof(bp->name) - 1, "Joy %d %s Axis (-)", i, joy[i].stick[j].axis[k].name); return 1; } } else if(joy[i].stick[j].axis[k].d2) { if(count == 0) { ignore[i][j][k] = 1; } else if(!ignore[i][j][k]) { bp->type = EOF_CONTROLLER_BUTTON_TYPE_JOYAXIS; bp->joy = i; bp->index = j; bp->key = k; bp->d = 1; (void) snprintf(bp->name, sizeof(bp->name) - 1, "Joy %d %s Axis (+)", i, joy[i].stick[j].axis[k].name); return 1; } } } } } count++; rest(10); } if(key[KEY_ESC]) { //If user pressed Escape, undefine this controller button (void) ustrcpy(bp->name, "(none)"); bp->type=bp->joy=bp->index=bp->d=bp->key=bp->held=bp->pressed=bp->released = 0; } return 0; }