//------------------------ Match keypress to item ------------------ int menu_match_keypress( MENU * menu, int keypress ) { int i; char c; char *letter; if ((keypress & KEY_CTRLED) || (keypress & KEY_SHIFTED)) return -1; keypress &= 0xFF; c = key_to_ascii(keypress); for (i=0; i< menu->NumItems; i++ ) { letter = strrchr( menu->Item[i].Text, CC_UNDERLINE ); if (letter) { letter++; if (c==tolower(*letter)) return i; } } return -1; }
void frontnet_start_input(void) { if (lbInkey & 0x80) { lbInkey = 0; return; } if (lbInkey != KC_UNASSIGNED) { unsigned short asckey; asckey = key_to_ascii(lbInkey, KMod_SHIFT); if ((lbInkey == KC_BACK) || (lbInkey == KC_RETURN) || (frontend_font_char_width(1, asckey) > 0)) { struct ScreenPacket *nspck; nspck = &net_screen_packet[my_player_number]; if ((nspck->field_4 & 0xF8) == 0) { nspck->field_4 = (nspck->field_4 & 7) | 0x40; nspck->param1 = lbInkey; if ((lbKeyOn[KC_LSHIFT] == 0) && (lbKeyOn[KC_RSHIFT] == 0)) { nspck->param2 = 0; lbInkey = 0; return; } nspck->param2 = 1; } } lbInkey = 0; } }
//palauttaa -1 jos ei löydetty bufferista merkkejä ja muita <0-lukuja muina //virheinä int vt_get_next_char(struct vt_file *f) { struct vt *vtptr; if (!f || !(vtptr = f->vtptr)) return -5; if(!initialized) return -5; for(;;){ int keyevent = vt_get_and_parse_next_key_event(f); if(keyevent<0){ //kprintf("[<0]"); return keyevent; } //kprintf("[%x]", keyevent); unsigned char code = keyevent & 0xff; unsigned char up = (keyevent & 0x100)?1:0; if(code == KEYCODE_LSHIFT || code == KEYCODE_RSHIFT || code == KEYCODE_LCTRL || code == KEYCODE_RCTRL || code == KEYCODE_LALT || code == KEYCODE_ALTGR || code == KEYCODE_SCROLL_LOCK || code == KEYCODE_CAPSLOCK || code == KEYCODE_NUMLOCK) continue; //kprintf("[c=%i|u=%i]", code, up); if(!up){ //kprintf(" [%s] ",(vtptr->kb_mods&(KEYB_MOD_LSHIFT|KEYB_MOD_RSHIFT))?"s":"n"); //kprintf(" [[%s]] ",(vtptr->kb_mods&(KEYB_MOD_CAPS))?"c":"n"); int c = key_to_ascii(code, vtptr->kb_mods); /*kprintf("[%x]", c); while(1);*/ return c; } } return -6; }
void frontnet_start_input(void) { //_DK_frontnet_start_input(); if (lbInkey & 0x80) { lbInkey = 0; return; } if (lbInkey != 0) { unsigned short asckey; asckey = key_to_ascii(lbInkey, KMod_SHIFT); if ((lbInkey == 14) || (lbInkey == 28) || (frontend_font_char_width(1,asckey) > 0)) { struct ScreenPacket *nspck; nspck = &net_screen_packet[my_player_number]; if ((nspck->field_4 & 0xF8) == 0) { nspck->field_4 = (nspck->field_4 & 7) | 0x40; nspck->param1 = lbInkey; if ((lbKeyOn[42] == 0) && (lbKeyOn[54] == 0)) { nspck->param2 = 0; lbInkey = 0; return; } nspck->param2 = 1; } } lbInkey = 0; } }
// maybe process a keypress in text messaging mode, return true if the key was processed int multi_msg_text_process(int k) { char str[2]; // keep eating keys for a short period of time if((Multi_msg_eat_stamp != -1) && !timestamp_elapsed(Multi_msg_eat_stamp)){ return 1; } // if we're not in text message mode, return 0 if(!Multi_msg_text_enter){ return 0; } switch(k){ // cancel the message case KEY_ESC: multi_msg_text_flush(); break; // send the message case KEY_ENTER: multi_msg_eval_text_msg(); multi_msg_text_flush(); break; // backspace case KEY_BACKSP: if(Multi_msg_text[0] != '\0'){ Multi_msg_text[strlen(Multi_msg_text)-1] = '\0'; } break; // ignore these individual keys case KEY_LSHIFT + KEY_SHIFTED: case KEY_RSHIFT + KEY_SHIFTED: case KEY_LALT + KEY_SHIFTED: case KEY_RALT + KEY_SHIFTED: case KEY_LCTRL + KEY_SHIFTED: case KEY_RCTRL + KEY_SHIFTED: break; // stick other printable characters onto the text default : // if we're not already at the maximum length if(strlen(Multi_msg_text) < MULTI_MSG_MAX_LEN){ str[0] = (char)key_to_ascii(k); str[1] = '\0'; strcat_s(Multi_msg_text,str); } break; } return 1; }
void ui_inputbox_do( UI_GADGET_INPUTBOX * inputbox, int keypress ) { char ascii; inputbox->oldposition = inputbox->position; inputbox->pressed=0; if (CurWindow->keyboard_focus_gadget==(UI_GADGET *)inputbox) { switch( keypress ) { case 0: break; case (KEY_LEFT): case (KEY_BACKSP): if (inputbox->position > 0) inputbox->position--; inputbox->text[inputbox->position] = 0; inputbox->status = 1; if (inputbox->first_time) inputbox->first_time = 0; break; case (KEY_ENTER): inputbox->pressed=1; inputbox->status = 1; if (inputbox->first_time) inputbox->first_time = 0; break; default: ascii = key_to_ascii(keypress); if ((ascii < 255 ) && (inputbox->position < inputbox->length-2)) { if (inputbox->first_time) { inputbox->first_time = 0; inputbox->position = 0; } inputbox->text[inputbox->position++] = ascii; inputbox->text[inputbox->position] = 0; } inputbox->status = 1; break; } } else { inputbox->first_time = 1; } last_keypress=0; ui_draw_inputbox( inputbox ); }
// if the passed key is keypad number, return the ascii value, otherwise -1 int keypad_to_ascii(int c) { switch(c){ case KEY_PAD0: case KEY_PAD1: case KEY_PAD2: case KEY_PAD3: case KEY_PAD4: case KEY_PAD5: case KEY_PAD6: case KEY_PAD7: case KEY_PAD8: case KEY_PAD9: case KEY_PADPERIOD: return key_to_ascii(c); break; default : return -1; break; } }
void UI_INPUTBOX::process(int focus) { int ascii, clear_lastkey, key, key_used, key_check; // check if mouse is pressed if (B1_PRESSED && is_mouse_on()) { set_focus(); } if (disabled_flag) return; if (my_wnd->selected_gadget == this) focus = 1; key_used = 0; changed_flag = 0; oldposition = position; pressed_down = 0; clear_lastkey = (flags & UI_INPUTBOX_FLAG_KEYTHRU) ? 0 : 1; if (focus) { key = my_wnd->keypress; switch (key) { case 0: break; //case KEY_LEFT: case KEY_BACKSP: if (position > 0) position--; text[position] = 0; if (flags & UI_INPUTBOX_FLAG_PASSWD) { passwd_text[position] = 0; } changed_flag = 1; key_used = 1; break; case KEY_ENTER: pressed_down = 1; locked = 0; changed_flag = 1; key_used = 1; break; case KEY_ESC: if (flags & UI_INPUTBOX_FLAG_ESC_CLR){ if (position > 0) { set_text(""); key_used = 1; } else { key_used = 0; clear_lastkey = 0; } } if (flags & UI_INPUTBOX_FLAG_ESC_FOC) { clear_focus(); } break; default: if (!locked) { // MWA -- determine if alt or ctrl held down on this key and don't process if it is. We // need to be able to pass these keys back to the top level. (And anyway -- ctrl-a shouldn't // print out an A in the input window if ( key & (KEY_ALTED | KEY_CTRLED) ) { clear_lastkey = 0; break; } // get an ascii char from the input if possible key_check = keypad_to_ascii(key); if(key_check == -1){ key_check = key_to_ascii(key); } ascii = validate_input(key_check); if ((ascii > 0) && (ascii < 255)) { if (flags & UI_INPUTBOX_FLAG_LETTER_FIRST) { if ((position == 0) && !is_letter((char) ascii)) break; } key_used = 1; if ( position < length ) { text[position] = (char) ascii; text[position + 1] = 0; if (flags & UI_INPUTBOX_FLAG_PASSWD) { passwd_text[position] = (char) INPUTBOX_PASSWD_CHAR; passwd_text[position + 1] = 0; } position++; // check to see if we should limit by pixel width if (pixel_limit > -1) { int _w; if (flags & UI_INPUTBOX_FLAG_PASSWD) { gr_get_string_size(&_w, NULL, passwd_text); } else { gr_get_string_size(&_w, NULL, text); } if (_w > pixel_limit) { position--; locked = 1; text[position] = 0; if (flags & UI_INPUTBOX_FLAG_PASSWD) { passwd_text[position] = 0; } } } } changed_flag = 1; } } break; } if (clear_lastkey || (key_used && (flags & UI_INPUTBOX_FLAG_EAT_USED)) ) my_wnd->last_keypress=0; } }
// if the passed key is keypad number, return the ascii value, otherwise -1 int keypad_to_ascii(int c) { switch(c){ case KEY_PAD0: return key_to_ascii(KEY_0); break; case KEY_PAD1: return key_to_ascii(KEY_1); break; case KEY_PAD2: return key_to_ascii(KEY_2); break; case KEY_PAD3: return key_to_ascii(KEY_3); break; case KEY_PAD4: return key_to_ascii(KEY_4); break; case KEY_PAD5: return key_to_ascii(KEY_5); break; case KEY_PAD6: return key_to_ascii(KEY_6); break; case KEY_PAD7: return key_to_ascii(KEY_7); break; case KEY_PAD8: return key_to_ascii(KEY_8); break; case KEY_PAD9: return key_to_ascii(KEY_9); break; case KEY_PADPERIOD: return key_to_ascii(KEY_PERIOD); break; default : return -1; break; } }
void debug_console(void (*_func)(void)) { int done = 0; while( key_inkey() ) { os_poll(); } if ( !debug_inited ) { dc_init(); } dc_draw(TRUE); while (!done) { // poll the os os_poll(); int k = key_inkey(); switch( k ) { case KEY_SHIFTED+KEY_ENTER: case KEY_ESC: done = TRUE; break; case KEY_BACKSP: if (!dc_command_buf.empty()) { dc_command_buf.erase(dc_command_buf.size() - 1); } break; case KEY_F3: case KEY_UP: if (last_oldcommand < (dc_history.end() - 1)) { ++last_oldcommand; } dc_command_buf = *last_oldcommand; break; case KEY_DOWN: if (last_oldcommand > dc_history.begin()) { --last_oldcommand; } dc_command_buf = *last_oldcommand; break; case KEY_PAGEUP: if (dc_scroll_y > 1) { dc_scroll_y--; } break; case KEY_PAGEDOWN: if (dc_scroll_y < (DBROWS - DROWS)) { dc_scroll_y++; } else { dc_scroll_y = (DBROWS - DROWS); } break; case KEY_ENTER: dc_scroll_y = (DBROWS - DROWS); // Set the scroll to look at the bottom last_oldcommand = dc_history.begin(); // Reset the last oldcommand lastline = 0; // Reset the line counter // Clear the command line on the window, but don't print the prompt until the command has processed // Stuff a copy of the command line onto the history // Search for the command // If not found: // abort, // dc_printf("Error: Invalid or Missing command %s", cmd.c_str()), and // dc_printf(dc_prompt) when ready for input // Call the function for that command, and strip the cmd token from the command line string if (dc_command_buf.empty()) { dc_printf("No command given.\n"); break; } // Else, continue to process the cmd_line // z64: Thread Note: Maybe lock a mutex here to allow a previous DCF to finish/abort before starting a new one // z64: We'll just assume we won't be here unless a command has finished... dc_history.push_front(dc_command_buf); // Push the command onto the history queue last_oldcommand = dc_history.begin(); // Reset oldcommand while (dc_history.size() > DCMDS) { dc_history.pop_back(); // Keep the commands less than or equal to DCMDS } dc_command_str = dc_command_buf; // Xfer to the command string for processing dc_command_buf.resize(0); // Nullify the buffer dc_printf("%s%s\n", dc_prompt, dc_command_str.c_str()); // Print the command w/ prompt. dc_draw(FALSE); // Redraw the console without the command line. dc_do_command(&dc_command_str); // Try to do the command break; default: // Not any of the control key codes, so it's probably a letter or number. ubyte c = (ubyte)key_to_ascii(k); if ((c != 255) && (dc_command_buf.size() < MAX_CLI_LEN)) { dc_command_buf.push_back(c); } } // Do the passed function if ( _func ) { _func(); } // All done, and ready for new entry dc_draw(TRUE); } while( key_inkey() ) { os_poll(); } }
/** * Does high score table new entry input. * @return True if the entry input is active, false otherwise. */ TbBool frontend_high_score_table_input(void) { struct HighScore *hscore; char chr; long i; if (high_score_entry_input_active >= campaign.hiscore_count) high_score_entry_input_active = -1; if (high_score_entry_input_active < 0) return false; if (lbInkey == KC_BACK) { // Delete previous character if (high_score_entry_index > 0) { i = high_score_entry_index-1; while (high_score_entry[i] != '\0') { high_score_entry[i] = high_score_entry[i+1]; i++; } high_score_entry_index -= 1; } clear_key_pressed(KC_BACK); return true; } if (lbInkey == KC_DELETE) { // Delete next character i = high_score_entry_index; while (high_score_entry[i] != '\0') { high_score_entry[i] = high_score_entry[i+1]; i++; } clear_key_pressed(KC_DELETE); return true; } if (lbInkey == KC_LEFT) { // Move cursor left if (high_score_entry_index > 0) { high_score_entry_index--; } clear_key_pressed(KC_LEFT); return true; } if (lbInkey == KC_RIGHT) { // Move cursor right i = high_score_entry_index; if (high_score_entry[i] != '\0') { high_score_entry_index++; } clear_key_pressed(KC_RIGHT); return true; } if ((lbInkey == KC_HOME) || (lbInkey == KC_PGUP)) { // Move cursor to beginning. high_score_entry_index = 0; clear_key_pressed(lbInkey); } if ((lbInkey == KC_END) || (lbInkey == KC_PGDOWN)) { // Move cursor to end. while (high_score_entry[high_score_entry_index] != '\0') { high_score_entry_index++; } clear_key_pressed(lbInkey); } if ((lbInkey == KC_RETURN) || (lbInkey == KC_NUMPADENTER) || (lbInkey == KC_ESCAPE)) { hscore = &campaign.hiscore_table[high_score_entry_input_active]; if (lbInkey == KC_ESCAPE) { strncpy(hscore->name, get_string(GUIStr_TeamLeader), HISCORE_NAME_LENGTH); } else { strncpy(hscore->name, high_score_entry, HISCORE_NAME_LENGTH); } high_score_entry_input_active = -1; save_high_score_table(); clear_key_pressed(lbInkey); return true; } if (high_score_entry_index < HISCORE_NAME_LENGTH) { chr = key_to_ascii(lbInkey, key_modifiers); if (chr != 0) { int entry_len; entry_len = strlen(high_score_entry); LbTextSetFont(frontend_font[1]); i = LbTextCharWidth(chr); if ((entry_len < (HISCORE_NAME_LENGTH - 1)) && ((i > 0) && (i + LbTextStringWidth(high_score_entry) < 308))) { i = entry_len; high_score_entry[i+1] = '\0'; while (i > high_score_entry_index) { high_score_entry[i] = high_score_entry[i-1]; i--; } high_score_entry[i] = chr; high_score_entry_index = i + 1; clear_key_pressed(lbInkey); return true; } } } // No input, but return true to make sure other input functions are skipped return true; }
// do any key processing here // input: pi => data about the popup // k => key that was pressed // // exit: 0 .. nchoices-1 => choice selected through keypress // POPUP_ABORT => abort the popup // POPUP_NOCHANGE => nothing happenned int popup_process_keys(popup_info *pi, int k, int flags) { int i, masked_k; if ( k <= 0 ) { return POPUP_NOCHANGE; } for ( i = 0; i < pi->nchoices; i++ ) { if ( pi->keypress[i] == key_to_ascii(k) ) { Popup_default_choice=i; Popup_buttons[i].press_button(); return i; } } switch(k) { case KEY_ENTER: // select the current default choice return Popup_default_choice; break; case KEY_ESC: // only process the escape key if this flag is not set if(!(flags & PF_IGNORE_ESC)){ return POPUP_ABORT; } break; case KEY_DOWN: case KEY_PAD2: case KEY_TAB: popup_play_default_change_sound(pi); Popup_default_choice++; if ( Popup_default_choice >= pi->nchoices ) { Popup_default_choice=0; } break; case KEY_UP: case KEY_PAD8: case KEY_SHIFTED+KEY_TAB: popup_play_default_change_sound(pi); Popup_default_choice--; if ( Popup_default_choice < 0 ) { Popup_default_choice=pi->nchoices-1; } break; default: break; } // end switch masked_k = k & ~KEY_CTRLED; // take out CTRL modifier only if ( (Game_mode & GM_IN_MISSION) ) { process_set_of_keys(masked_k, Dead_key_set_size, Dead_key_set); button_info_do(&Player->bi); // call functions based on status of button_info bit vectors } return POPUP_NOCHANGE; }
void main (void) { char ascii; int c; setbuf( stdout, NULL ); key_init(); //timer_init( 0, NULL ); //keyd_buffer_type = 2; keyd_repeat = 0; printf( "\n\n\n\nThis tests the keyboard library.\n\n" ); printf( "Press any key to start...\n" ); printf( "You pressed: %c\n\n", key_getch() ); printf( "Press F1 to turn off buffering.\n" ); printf( " F2 to turn on buffering.\n" ); printf( " F4 to flush keyboard.\n" ); printf( " F5 to turn repeat off.\n"); printf( " F6 to turn repeat on.\n"); printf( " F7 to do an INT 3.\n" ); printf( " F10 to display some boxes.\n" ); printf( " The arrows to see fast multiple keystrokes.\n"); printf( " ESC to exit.\n\n" ); while( !keyd_pressed[KEY_ESC] ) { int i,j; for (i=0; i<256; i++ ) { if (keyd_pressed[i]) { j = key_to_ascii(i); if (j==255) vidmem[i*2] = 219; else vidmem[i*2] = j; } else vidmem[i*2] = 32; } if (keyd_pressed[KEY_F1]) keyd_buffer_type = 0; if (keyd_pressed[KEY_F2]) keyd_buffer_type = 1; if (keyd_pressed[KEY_F4]) key_flush(); if (keyd_pressed[KEY_F5]) { keyd_repeat = 0; printf( "Repeat off" ); } if (keyd_pressed[KEY_F6]) { keyd_repeat = 1; printf( "Repeat on" ); } // if (keyd_pressed[KEY_F7] ) // key_debug(); if (keyd_pressed[KEY_PAUSE]) putch( 254 ); if (key_checkch()) { c = key_getch(); ascii=key_to_ascii(c); if ( ascii==255 ) { printf("[%4X] ", c ); fflush( stdout ); } else putch( ascii ); if (c==1) break; } delay(100); } key_close(); //timer_close(); }
void debug_console( void (*_func)() ) { int done = 0; scanner_init(); while( key_inkey() ) { os_poll(); } if ( !debug_inited ) { debug_init(); } debug_draw(); while (!done) { // poll the os os_poll(); int k = key_inkey(); switch( k ) { case KEY_SHIFTED+KEY_ENTER: case KEY_ESC: done=1; break; case KEY_BACKSP: if ( command_line_pos > 0 ) { command_line[--command_line_pos] = 0; } break; case KEY_F3: if ( last_oldcommand > -1 ) { strcpy_s( command_line, oldcommand_line[last_oldcommand] ); command_line_pos = strlen(command_line); command_line[command_line_pos] = 0; } break; case KEY_UP: command_scroll--; if (command_scroll<0) { command_scroll = last_oldcommand; } if ( command_scroll > -1 ) { strcpy_s( command_line, oldcommand_line[command_scroll] ); command_line_pos = strlen(command_line); command_line[command_line_pos] = 0; } break; case KEY_DOWN: command_scroll++; if (command_scroll>last_oldcommand) { command_scroll = 0; } if (command_scroll>last_oldcommand) { command_scroll = -1; } if ( command_scroll > -1 ) { strcpy_s( command_line, oldcommand_line[command_scroll] ); command_line_pos = strlen(command_line); command_line[command_line_pos] = 0; } break; case KEY_ENTER: { debug_output( '\n' ); debug_draw(); debug_do_command(command_line); int i, found = 0; for (i=0; i<=last_oldcommand; i++ ) { if (!stricmp( oldcommand_line[i], command_line )) { found = 1; } } if ( !found ) { if ( last_oldcommand < DEBUG_HISTORY-1 ) { last_oldcommand++; strcpy_s( oldcommand_line[last_oldcommand], command_line); } else { int iLoop; for (iLoop=0; iLoop<last_oldcommand; iLoop++ ) { strcpy_s( oldcommand_line[iLoop], oldcommand_line[iLoop+1] ); } strcpy_s( oldcommand_line[last_oldcommand], command_line); } } debug_output( '\n' ); command_line_pos = 0; command_line[command_line_pos] = 0; command_scroll = 0; } break; default: { ubyte c = (ubyte)key_to_ascii(k); if ( c != 255 ) { command_line[command_line_pos++] = c; command_line[command_line_pos] = 0; } } } strcpy_s( debug_text[debug_y], ">" ); strcat_s( debug_text[debug_y], command_line ); debug_draw(); if ( _func ) { _func(); } } while( key_inkey() ) { os_poll(); } }