void KeyListener::Add(std::vector<std::string> keys, const char* message, bool isGlobal) { // Discard the hot key if it has three or more keys in it. if (keys.size() > 2) return; std::cout << "Adding Hot Key: " << keys[0]; unsigned int modCode = 0, keyCode; // Get the code for the modifier, if there is one. if (keys.size() == 2) { modCode = get_key_code(keys[0].c_str()); std::cout << "(" << modCode << ") + " << keys[1]; } // Get the code for the key itself. keyCode = get_key_code(keys[keys.size() - 1].c_str()); std::cout << "(" << keyCode << ")" << std::endl; // Register the new binding. KeyBinding* binding = new KeyBinding(modCode, keyCode, message, isGlobal, keyboardLayout); binding->Register(bindings.size()); bindings.push_back(binding); }
static void install_keybinding(char *key,char *value){ int keycode; char *edit_name,*terminate_name; int i,edit_code,terminate_value; keycode=get_key_code(key); if (keycode < 0) return ; /* unknown key */ edit_name = strtok(value," \t"); terminate_name = strtok(NULL," \t"); if (edit_name == NULL) return; /* no action defined */ edit_code=get_edit_code(edit_name); if (terminate_name) terminate_value=atoi(terminate_name); else terminate_value = 0; i=0; while(keyBindings[i].keyCode){ if (keyBindings[i].keyCode==keycode){ keyBindings[i].action=edit_code; keyBindings[i].screenStatus=terminate_value; return; } i++; } return; }
gcc_pure static bool check_key(ContainerWindow *container, const SDL_Event &event) { Window *focused = container->get_focused_window(); if (focused == NULL) return false; return focused->on_key_check(get_key_code(event)); }
int main(void) { uint8_t keyCode = CHESS_KEY_NONE; uint8_t is_redraw = 1; u8g_t u8g; u8g_Init(&u8g, &u8g_dev_sdl_2bit); u8g_FirstPage(&u8g); chess_Init(&u8g, 0); #ifdef PERFTEST chess_Step(CHESS_KEY_SELECT); chess_Step(CHESS_KEY_NONE); chess_Step(CHESS_KEY_NEXT); chess_Step(CHESS_KEY_NONE); chess_Step(CHESS_KEY_NEXT); chess_Step(CHESS_KEY_NONE); #endif for(;;) { if ( is_redraw != 0 ) { #ifdef PERFTEST int i; for( i = 0; i < 500; i++ ) { #endif u8g_FirstPage(&u8g); do { chess_Draw(); } while( u8g_NextPage(&u8g) ); #ifdef PERFTEST } #endif is_redraw--; } #ifdef PERFTEST exit(0); #endif keyCode = get_key_code(); if ( keyCode != CHESS_KEY_NONE ) { is_redraw = 2; chess_Step(keyCode); } chess_Step(CHESS_KEY_NONE); } }
static int getch_with_delay (void) { int c; while (1) { /* Try to get a character */ c = get_key_code (0); if (c != ERR) break; } /* Success -> return the character */ return c; }
bool keyboard_shortcut_manager_v2::pretranslate_message(const MSG * msg, HWND thisPopupWnd) { switch(msg->message) { case WM_KEYDOWN: case WM_SYSKEYDOWN: if (thisPopupWnd != NULL && FindOwningPopup(msg->hwnd) == thisPopupWnd) { const t_uint32 modifiers = GetHotkeyModifierFlags(); if (filterTypableWindowMessage(msg, modifiers)) { if (process_keydown_simple(get_key_code(msg->wParam,modifiers))) return true; } } return false; default: return false; } }
static int key_release_callback(void * data, int key, int mask) { VisEventQueue *eventqueue; int lv_key, lv_mask; lv_priv_t * priv = (lv_priv_t*)data; if(!get_key_code(key, mask, &lv_key, &lv_mask)) return 0; eventqueue = visual_plugin_get_eventqueue(visual_actor_get_plugin(priv->actor)); visual_event_queue_add_keyboard(eventqueue, lv_key, lv_mask, VISUAL_KEY_UP); return 1; }
//------------------------------------------------------------------------------ // @fn main //! //! Core of "main_interrupt_example.c". //! //! Display in decimal on DVK90CAN1 board the seconds, minutes, hours & days //! given by the Unit declared as RTC. //! - NO key = seconds //! - NORTH key = minutes //! - CENTER key = hours //! - SOUTH key = days //! //! @warning Care on "#define"'s in "config.h". //! //! @param none. //! //! @return Integer 0 //! //------------------------------------------------------------------------------ int main (void) { U8 temp1, temp2; asm("cli"); //--- I N I T // --- Clock prescaler Reset CLKPR = 0x80; CLKPR = 0x00; // --- Init LED's & Keys led_init(); key_init(); // --- Init "SECOND COUNTER" rtc_int_init(); //--- C O R E O F T H E M A I N while(1) { //- Get display order switch (get_key_code()) { case BUTTON_S_CODE: // South for days display temp1 = rtc_days; break; case BUTTON_C_CODE: // Center for hours display temp1 = rtc_hours; break; case BUTTON_N_CODE: // North for minutes display temp1 = rtc_minutes; break; default: // Nothing for seconds display temp1 = rtc_seconds; break; } //- Display in decimal temp2 = temp1 % 10; temp2 |= (temp1/10)<<4; write_led(temp2); } return 0; }
static void fill_keys_array(int (*keys_array)[MAX_KEYS_PER_GESTURE], char *keys) { if (keys) { char *ptr = strtok(keys, "+"); uint8_t i = 0; while (ptr) { if (i >= MAX_KEYS_PER_GESTURE) { fprintf(stderr, "error: for each gesture only %d keystrokes are allowed\n", MAX_KEYS_PER_GESTURE); exit(EXIT_FAILURE); } int key_code = get_key_code(ptr); if (key_code < 0) { fprintf(stderr, "error: wrong key name '%s'\n", ptr); exit(EXIT_FAILURE); } (*keys_array)[i] = key_code; ptr = strtok(NULL, "+"); i++; } } }
char request_char(const buffer * const b, const char * const prompt, const char default_value) { set_attr(0); print_prompt(prompt); if (default_value) output_char(default_value, 0, false); move_cursor(b->cur_y, b->cur_x); while(true) { int c; input_class ic; do c = get_key_code(); while(c > 0xFF || (ic = CHAR_CLASS(c)) == IGNORE || ic == INVALID); switch(ic) { case ALPHA: return (char)localised_up_case[(unsigned char)c]; case RETURN: return (char)localised_up_case[(unsigned char)default_value]; default: break; } } }
/* Returns a character read from stdin with appropriate interpretation */ int get_event (Gpm_Event *event, int redo_event, int block) { int c; static int flag; /* Return value from select */ static int dirty = 3; if ((dirty == 1) || is_idle ()){ refresh (); doupdate (); dirty = 1; } else dirty++; vfs_timeout_handler (); c = block ? getch_with_delay () : get_key_code (1); if (!c) { /* Code is 0, so this is a Control key or mouse event */ return EV_NONE; /* FIXME: mouse not supported */ } return c; }
void toggle_panels (void) { #ifdef ENABLE_SUBSHELL vfs_path_t *new_dir_vpath = NULL; #endif /* ENABLE_SUBSHELL */ SIG_ATOMIC_VOLATILE_T was_sigwinch = 0; channels_down (); disable_mouse (); disable_bracketed_paste (); if (clear_before_exec) clr_scr (); if (mc_global.tty.alternate_plus_minus) numeric_keypad_mode (); #ifndef HAVE_SLANG /* With slang we don't want any of this, since there * is no raw_mode supported */ tty_reset_shell_mode (); #endif /* !HAVE_SLANG */ tty_noecho (); tty_keypad (FALSE); tty_reset_screen (); do_exit_ca_mode (); tty_raw_mode (); if (mc_global.tty.console_flag != '\0') handle_console (CONSOLE_RESTORE); #ifdef ENABLE_SUBSHELL if (mc_global.tty.use_subshell) { vfs_path_t **new_dir_p; new_dir_p = vfs_current_is_local ()? &new_dir_vpath : NULL; invoke_subshell (NULL, VISIBLY, new_dir_p); } else #endif /* ENABLE_SUBSHELL */ { if (output_starts_shell) { fprintf (stderr, _("Type 'exit' to return to the Midnight Commander")); fprintf (stderr, "\n\r\n\r"); my_system (EXECUTE_INTERNAL, mc_global.tty.shell, NULL); } else get_key_code (0); } if (mc_global.tty.console_flag != '\0') handle_console (CONSOLE_SAVE); do_enter_ca_mode (); tty_reset_prog_mode (); tty_keypad (TRUE); /* Prevent screen flash when user did 'exit' or 'logout' within subshell */ if ((quit & SUBSHELL_EXIT) != 0) { /* User did 'exit' or 'logout': quit MC */ if (quiet_quit_cmd ()) return; quit = 0; #ifdef ENABLE_SUBSHELL /* restart subshell */ if (mc_global.tty.use_subshell) init_subshell (); #endif /* ENABLE_SUBSHELL */ } enable_mouse (); enable_bracketed_paste (); channels_up (); if (mc_global.tty.alternate_plus_minus) application_keypad_mode (); /* HACK: * Save sigwinch flag that will be reset in mc_refresh() called via update_panels(). * There is some problem with screen redraw in ncurses-based mc in this situation. */ was_sigwinch = mc_global.tty.winch_flag; mc_global.tty.winch_flag = 0; #ifdef ENABLE_SUBSHELL if (mc_global.tty.use_subshell) { do_load_prompt (); if (new_dir_vpath != NULL) do_possible_cd (new_dir_vpath); if (mc_global.tty.console_flag != '\0' && output_lines) show_console_contents (output_start_y, LINES - mc_global.keybar_visible - output_lines - 1, LINES - mc_global.keybar_visible - 1); } vfs_path_free (new_dir_vpath); #endif /* ENABLE_SUBSHELL */ if (mc_global.mc_run_mode == MC_RUN_FULL) { update_panels (UP_OPTIMIZE, UP_KEEPSEL); update_xterm_title_path (); } if (was_sigwinch != 0 || mc_global.tty.winch_flag != 0) dialog_change_screen_size (); else repaint_screen (); }
int request_strings(req_list *rlp0, int n) { assert(rlp0->cur_entries > 0); int ne_lines0 = 0, ne_columns0 = 0; bool reordered = false; max_names_per_line = max_names_per_col = x = y = page = fuzz_len = 0; if ( ! request_strings_init(rlp0) ) return ERROR; const int dx = rl.max_entry_len + 1 + (rl.suffix ? 1 : 0); while(true) { if (ne_lines0 != ne_lines || ne_columns0 != ne_columns) { if (ne_lines0 && ne_columns0 ) n = PXY2N(page,x,y); if (!(max_names_per_line = ne_columns / dx)) max_names_per_line = 1; max_names_per_col = ne_lines - 1; names_per_page = max_names_per_line * max_names_per_col; ne_lines0 = ne_lines; ne_columns0 = ne_columns; page = N2P(n); x = N2X(n); y = N2Y(n); print_strings(); print_message(NULL); } n = PXY2N(page,x,y); assert(fuzz_len >= 0); fuzz_len = min(fuzz_len, strlen(rl.entries[n])); move_cursor(y, x * dx + fuzz_len); int c; input_class ic; do c = get_key_code(); while((ic = CHAR_CLASS(c)) == IGNORE || ic == INVALID); switch(ic) { case ALPHA: if (n >= rl.cur_entries) n = rl.cur_entries - 1; c = localised_up_case[(unsigned char)c]; fuzz_forward( c ); break; case TAB: if (! rlp0->ignore_tab) { n = request_strings_cleanup(reordered); if (n >= rlp0->cur_entries) return ERROR; else return -n - 2; } break; case RETURN: n = request_strings_cleanup(reordered); if (n >= rlp0->cur_entries) return ERROR; else return n; case COMMAND: if (c < 0) c = -c - 1; const int a = parse_command_line(key_binding[c], NULL, NULL, false); if (a >= 0) { switch(a) { case BACKSPACE_A: fuzz_back(); break; case MOVERIGHT_A: request_move_right(); break; case MOVELEFT_A: request_move_left(); break; case MOVESOL_A: request_move_to_sol(); break; case MOVEEOL_A: request_move_to_eol(); break; case TOGGLESEOL_A: if (x != 0) x = 0; else request_move_to_eol(); break; case LINEUP_A: request_move_up(); break; case LINEDOWN_A: request_move_down(); break; case MOVEINCUP_A: request_move_inc_up(); break; case MOVEINCDOWN_A: request_move_inc_down(); break; case PAGEUP_A: case PREVPAGE_A: request_prev_page(); break; case PAGEDOWN_A: case NEXTPAGE_A: request_next_page(); break; case MOVESOF_A: request_move_to_sof(); break; case MOVEEOF_A: request_move_to_eof(); break; case TOGGLESEOF_A: request_toggle_seof(); break; case NEXTWORD_A: request_move_next(); break; case PREVWORD_A: request_move_previous(); break; case NEXTDOC_A: reordered |= request_reorder(1); break; case PREVDOC_A: reordered |= request_reorder(-1); break; case INSERT_A: case DELETECHAR_A: prune = !prune; break; case CLOSEDOC_A: case ESCAPE_A: case QUIT_A: case SELECTDOC_A: request_strings_cleanup(reordered); return -1; } } break; default: break; } } }
int WndForm::ShowModal() { assert_none_locked(); #define OPENCLOSESUPPRESSTIME 500 #ifndef USE_GDI ContainerWindow *root = get_root_owner(); WindowReference old_focus_reference = root->GetFocusedWindowReference(); #else HWND oldFocusHwnd; #endif /* USE_GDI */ PeriodClock enter_clock; if (is_embedded() && !is_altair()) enter_clock.update(); show_on_top(); mModalResult = 0; #ifdef USE_GDI oldFocusHwnd = ::GetFocus(); if (oldFocusHwnd != NULL) ::SendMessage(oldFocusHwnd, WM_CANCELMODE, 0, 0); #endif /* USE_GDI */ set_focus(); focus_first_control(); bool hastimed = false; WndForm::timeAnyOpenClose.update(); // when current dlg opens or child closes main_window.add_dialog(this); #ifndef USE_GDI main_window.refresh(); #endif #ifdef ANDROID EventLoop loop(*event_queue, main_window); Event event; #elif defined(ENABLE_SDL) EventLoop loop(main_window); SDL_Event event; #else DialogEventLoop loop(*this); MSG event; #endif while ((mModalResult == 0 || force) && loop.get(event)) { #if defined(ENABLE_SDL) && !defined(ANDROID) if (event.type == SDL_QUIT) { mModalResult = mrCancel; continue; } #endif if (!main_window.FilterEvent(event, this)) continue; // hack to stop exiting immediately if (is_embedded() && !is_altair() && !hastimed && is_user_input(event)) { if (!enter_clock.check(200)) /* ignore user input in the first 200ms */ continue; else hastimed = true; } if (is_embedded() && is_mouse_up(event) && !timeAnyOpenClose.check(OPENCLOSESUPPRESSTIME)) /* prevents child click from being repeat-handled by parent if buttons overlap */ continue; if (mOnKeyDownNotify != NULL && is_key_down(event) && #ifdef USE_GDI identify_descendant(event.hwnd) && #endif !check_special_key(this, event) && mOnKeyDownNotify(*this, get_key_code(event))) continue; #if defined(ENABLE_SDL) && !defined(ANDROID) if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_TAB) { /* the Tab key moves the keyboard focus */ const Uint8 *keystate = ::SDL_GetKeyState(NULL); event.key.keysym.sym = keystate[SDLK_LSHIFT] || keystate[SDLK_RSHIFT] ? SDLK_UP : SDLK_DOWN; } #endif if (is_key_down(event) && #ifdef USE_GDI identify_descendant(event.hwnd) && #endif (get_key_code(event) == VK_UP || get_key_code(event) == VK_DOWN)) { /* VK_UP and VK_DOWN move the focus only within the current control group - but we want it to behave like Shift-Tab and Tab */ if (!check_key(this, event)) { /* this window doesn't handle VK_UP/VK_DOWN */ if (get_key_code(event) == VK_DOWN) focus_next_control(); else focus_previous_control(); continue; } } #ifndef USE_GDI if (is_key_down(event) && get_key_code(event) == VK_ESCAPE) { mModalResult = mrCancel; continue; } #endif /* map VK_ESCAPE to mrOK on Altair, because the Escape key is expected to be the one that saves and closes a dialog */ if (is_altair() && is_key_down(event) && get_key_code(event) == VK_ESCAPE) { mModalResult = mrOK; continue; } loop.dispatch(event); } // End Modal Loop main_window.remove_dialog(this); // static. this is current open/close or child open/close WndForm::timeAnyOpenClose.update(); #ifdef USE_GDI SetFocus(oldFocusHwnd); #else if (old_focus_reference.Defined()) { Window *old_focus = old_focus_reference.Get(*root); if (old_focus != NULL) old_focus->set_focus(); } #endif /* !USE_GDI */ return mModalResult; }
gcc_pure static bool check_special_key(ContainerWindow *container, const SDL_Event &event) { return is_special_key(get_key_code(event)) && check_key(container, event); }
int main(int argc, char **argv) { char *locale = setlocale(LC_ALL, ""); for(int i = 0; i < 256; i++) localised_up_case[i] = toupper(i); if (locale) { struct re_pattern_buffer re_pb; struct re_registers re_reg; memset(&re_pb, 0, sizeof re_pb); memset(&re_reg, 0, sizeof re_reg); re_pb.translate = localised_up_case; re_compile_pattern(LOCALE_REGEX, strlen(LOCALE_REGEX), &re_pb); if (re_search(&re_pb, locale, strlen(locale), 0, strlen(locale), &re_reg) >= 0) { if (re_reg.start[1] >= 0) io_utf8 = true; } free(re_reg.start); free(re_reg.end); } bool no_config = false; char *macro_name = NULL, *key_bindings_name = NULL, *menu_conf_name = NULL, *startup_prefs_name = DEF_PREFS_NAME; char * const skiplist = calloc(argc, 1); if (!skiplist) exit(1); /* We need this many flags. */ for(int i = 1; i < argc; i++) { if (argv[i][0] == '-' && (!strcmp(&argv[i][1], "h") || !strcmp(&argv[i][1], "-help" "\0" VERSION_STRING))) { puts(ARG_HELP); exit(0); } /* Special arguments start with two dashes. If we find one, we cancel its entry in argv[], so that it will be skipped when opening the specified files. The only exception is +N for skipping to the N-th line. */ if (argv[i][0] == '-' && argv[i][1] == '-') { if (!argv[i][2]) i++; /* You can use "--" to force the next token to be a filename */ else if (!strcmp(&argv[i][2], "noconfig") || !strcmp(&argv[i][2], "no-config")) { no_config = true; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "noansi") || !strcmp(&argv[i][2], "no-ansi")) { ansi = false; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "no-syntax")) { do_syntax = false; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "prefs")) { if (i < argc-1) { startup_prefs_name = argv[i+1]; skiplist[i] = skiplist[i+1] = 1; /* argv[i] = argv[i+1] = NULL; */ } } else if (!strcmp(&argv[i][2], "ansi")) { ansi = true; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "utf8")) { io_utf8 = true; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "no-utf8")) { io_utf8 = false; skiplist[i] = 1; /* argv[i] = NULL; */ } else if (!strcmp(&argv[i][2], "macro")) { if (i < argc-1) { macro_name = argv[i+1]; skiplist[i] = skiplist[i+1] = 1; /* argv[i] = argv[i+1] = NULL; */ } } else if (!strcmp(&argv[i][2], "keys")) { if (i < argc-1) { key_bindings_name = argv[i+1]; skiplist[i] = skiplist[i+1] = 1; /* argv[i] = argv[i+1] = NULL; */ } } else if (!strcmp(&argv[i][2], "menus")) { if (i < argc-1) { menu_conf_name = argv[i+1]; skiplist[i] = skiplist[i+1] = 1; /* argv[i] = argv[i+1] = NULL; */ } } } } #ifdef NE_TEST /* Dump the builtin menu and key bindings to compare to doc/default.menus and doc/default.keys. */ int dump_config(void); dump_config(); #endif /* Unless --noconfig was specified, we try to configure the menus and the keyboard. Note that these functions can exit() on error. */ if (!no_config) { get_menu_configuration(menu_conf_name); get_key_bindings(key_bindings_name); } /* If we cannot even create a buffer, better go... */ if (!new_buffer()) exit(1); /* Now that key_bindings are loaded, try to fix up the message for NOT_FOUND. */ { char *repeat_last_keystroke, *new_not_found; if ((repeat_last_keystroke = find_key_strokes(REPEATLAST_A, 1))) { if ((new_not_found = malloc(39+strlen(repeat_last_keystroke)))) { strcat(strcat(strcpy(new_not_found, "Not Found. (RepeatLast with "), repeat_last_keystroke), " to wrap.)"); error_msg[NOT_FOUND] = new_not_found; } free(repeat_last_keystroke); } } clear_buffer(cur_buffer); /* The INT_MAX clip always exists, and it is used by the Through command. */ clip_desc * const cd = alloc_clip_desc(INT_MAX, 0); if (!cd) exit(1); add_head(&clips, &cd->cd_node); /* General terminfo and cursor motion initalization. From here onwards, we cannot exit() lightly. */ term_init(); /* We will be always using the last line for the status bar. */ set_terminal_window(ne_lines-1); /* We read in all the key capabilities. */ read_key_capabilities(); /* Some initializations of other modules... */ re_set_syntax( RE_CONTEXT_INDEP_ANCHORS | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE | RE_NEWLINE_ALT | RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES ); bool first_file = true; load_virtual_extensions(); load_auto_prefs(cur_buffer, startup_prefs_name); buffer *stdin_buffer = NULL; if (!isatty(fileno(stdin))) { first_file = false; const int error = load_fd_in_buffer(cur_buffer, fileno(stdin)); print_error(error); stdin_buffer = cur_buffer; if (!(freopen("/dev/tty", "r", stdin))) { fprintf(stderr, "Cannot reopen input tty\n"); abort(); } } /* The terminal is prepared for interactive I/O. */ set_interactive_mode(); clear_entire_screen(); /* This function sets fatal_code() as signal interrupt handler for all the dangerous signals (SIGILL, SIGSEGV etc.). */ set_fatal_code(); if (argc > 1) { /* The first file opened does not need a NEWDOC_A action. Note that file loading can be interrupted (wildcarding can sometimes produce unwanted results). */ uint64_t first_line = 0, first_col = 0; bool binary = false, skip_plus = false, read_only = false; stop = false; for(int i = 1; i < argc && !stop; i++) { if (argv[i] && !skiplist[i]) { if (argv[i][0] == '+' && !skip_plus) { /* looking for "+", or "+N" or "+N,M" */ uint64_t tmp_l = INT64_MAX, tmp_c = 0; char *d; errno = 0; if (argv[i][1]) { if (isdigit((unsigned char)argv[i][1])) { tmp_l = strtoll(argv[i]+1, &d, 10); if (!errno) { if (*d) { /* separator between N and M */ if (isdigit((unsigned char)d[1])) { tmp_c = strtoll(d+1, &d, 10); if (*d) errno = ERANGE; } else errno = ERANGE; } } } else errno = ERANGE; } if (!errno) { first_line = tmp_l; first_col = tmp_c; } else { skip_plus = true; i--; } } else if (!strcmp(argv[i], "--binary")) { binary = true; } else if (!strcmp(argv[i], "--read-only") || !strcmp(argv[i], "--readonly") || !strcmp(argv[i], "--ro")) { read_only = true; } else { if (!strcmp(argv[i], "-") && stdin_buffer) { stdin_buffer->opt.binary = binary; if (read_only) stdin_buffer->opt.read_only = read_only; if (first_line) do_action(stdin_buffer, GOTOLINE_A, first_line, NULL); if (first_col) do_action(stdin_buffer, GOTOCOLUMN_A, first_col, NULL); stdin_buffer = NULL; } else { if (!strcmp(argv[i], "--")) i++; if (!first_file) do_action(cur_buffer, NEWDOC_A, -1, NULL); else first_file = false; cur_buffer->opt.binary = binary; if (i < argc) do_action(cur_buffer, OPEN_A, 0, str_dup(argv[i])); if (first_line) do_action(cur_buffer, GOTOLINE_A, first_line, NULL); if (first_col) do_action(cur_buffer, GOTOCOLUMN_A, first_col, NULL); if (read_only) cur_buffer->opt.read_only = read_only; } first_line = first_col = 0; skip_plus = binary = read_only = false; } } } free(skiplist); /* This call makes current the first specified file. It is called only if more than one buffer exist. */ if (get_nth_buffer(1)) do_action(cur_buffer, NEXTDOC_A, -1, NULL); } /* We delay updates. In this way the macro activity does not cause display activity. */ reset_window(); delay_update(); if (macro_name) do_action(cur_buffer, MACRO_A, -1, str_dup(macro_name)); else if (first_file) { /* If there is no file to load, and no macro to execute, we display the "NO WARRANTY" message. */ about(); } while(true) { /* If we are displaying the "NO WARRANTY" info, we should not refresh the window now */ if (!displaying_info) { refresh_window(cur_buffer); if (cur_buffer->opt.automatch) automatch_bracket(cur_buffer, true); } draw_status_bar(); move_cursor(cur_buffer->cur_y, cur_buffer->cur_x); int c = get_key_code(); if (window_changed_size) { print_error(do_action(cur_buffer, REFRESH_A, 0, NULL)); window_changed_size = displaying_info = false; cur_buffer->automatch.shown = 0; } if (c == INVALID_CHAR) continue; /* Window resizing. */ const input_class ic = CHAR_CLASS(c); if (displaying_info) { refresh_window(cur_buffer); displaying_info = false; } if (cur_buffer->automatch.shown) automatch_bracket(cur_buffer, false); switch(ic) { case INVALID: print_error(INVALID_CHARACTER); break; case ALPHA: print_error(do_action(cur_buffer, INSERTCHAR_A, c, NULL)); break; case TAB: print_error(do_action(cur_buffer, INSERTTAB_A, 1, NULL)); break; case RETURN: print_error(do_action(cur_buffer, INSERTLINE_A, -1, NULL)); break; case COMMAND: if (c < 0) c = -c - 1; if (key_binding[c]) print_error(execute_command_line(cur_buffer, key_binding[c])); break; default: break; } } }
bool keyboard_shortcut_manager::on_keydown_context(const pfc::list_base_const_t<metadb_handle_ptr> & data,WPARAM wp,const GUID & caller) { if (data.get_count()==0) return false; return process_keydown_ex(TYPE_CONTEXT,data,get_key_code(wp),caller); }
bool keyboard_shortcut_manager::on_keydown(shortcut_type type,WPARAM wp) { if (type==TYPE_CONTEXT) return false; metadb_handle_list dummy; return process_keydown(type,dummy,get_key_code(wp)); }
bool uie::window::g_process_keydown_keyboard_shortcuts(WPARAM wp) { return static_api_ptr_t<keyboard_shortcut_manager_v2>()->process_keydown_simple(get_key_code(wp)); }
char *request(const char *prompt, const char * const default_string, const bool alpha_allowed, const int completion_type, const bool prefer_utf8) { set_attr(0); input_buffer[pos = len = offset = 0] = 0; encoding = ENC_ASCII; x = start_x = print_prompt(prompt); init_history(); if (default_string) { strncpy(input_buffer, default_string, MAX_INPUT_LINE_LEN); len = strlen(input_buffer); encoding = detect_encoding(input_buffer, len); input_refresh(); } bool first_char_typed = true, last_char_completion = false, selection = false; while(true) { assert(input_buffer[len] == 0); move_cursor(ne_lines - 1, x); int c; input_class ic; do c = get_key_code(); while((ic = CHAR_CLASS(c)) == IGNORE); /* ISO 10646 characters *above 256* can be added only to UTF-8 lines, or ASCII lines (making them, of course, UTF-8). */ if (ic == ALPHA && c > 0xFF && encoding != ENC_ASCII && encoding != ENC_UTF8) ic = INVALID; if (ic != TAB) last_char_completion = false; if (ic == TAB && !completion_type) ic = ALPHA; switch(ic) { case INVALID: alert(); break; case ALPHA: if (first_char_typed) { input_buffer[len = 0] = 0; clear_to_eol(); } if (encoding == ENC_ASCII && c > 0x7F) encoding = prefer_utf8 || c > 0xFF ? ENC_UTF8 : ENC_8_BIT; int c_len = encoding == ENC_UTF8 ? utf8seqlen(c) : 1; int c_width = output_width(c); assert(c_len > 0); if (len <= MAX_INPUT_LINE_LEN - c_len && (alpha_allowed || (c < 0x100 && isxdigit(c)) || c=='X' || c=='x')) { memmove(&input_buffer[pos + c_len], &input_buffer[pos], len - pos + 1); if (c_len == 1) input_buffer[pos] = c; else utf8str(c, &input_buffer[pos]); len += c_len; move_cursor(ne_lines - 1, x); if (x < ne_columns - c_width) { if (pos == len - c_len) output_char(c, 0, encoding); else if (char_ins_del_ok) insert_char(c, 0, encoding); else input_refresh(); } input_move_right(true); } break; case RETURN: selection = true; break; case TAB: if (completion_type == COMPLETE_FILE || completion_type == COMPLETE_SYNTAX) { bool quoted = false; char *prefix, *completion, *p; if (len && input_buffer[len - 1] == '"') { input_buffer[len - 1] = 0; if (prefix = strrchr(input_buffer, '"')) { quoted = true; prefix++; } else input_buffer[len - 1] = '"'; } if (!quoted) { prefix = strrchr(input_buffer, ' '); if (prefix) prefix++; else prefix = input_buffer; } if (last_char_completion || completion_type == COMPLETE_SYNTAX) { if (completion_type == COMPLETE_FILE ) completion = p = request_files(prefix, true); else completion = p = request_syntax(prefix, true); reset_window(); if (completion) { if (*completion) selection = true; else completion++; } } else { if (completion_type == COMPLETE_FILE ) completion = p = complete_filename(prefix); else completion = p = request_syntax(prefix, true); last_char_completion = true; if (!completion) alert(); } if (completion && (prefix - input_buffer) + strlen(completion) + 1 < MAX_INPUT_LINE_LEN) { const encoding_type completion_encoding = detect_encoding(completion, strlen(completion)); if (encoding == ENC_ASCII || completion_encoding == ENC_ASCII || encoding == completion_encoding) { strcpy(prefix, completion); if (quoted) strcat(prefix, "\""); len = strlen(input_buffer); pos = offset = 0; x = start_x; if (encoding == ENC_ASCII) encoding = completion_encoding; input_move_to_eol(); if (quoted) input_move_left(false); input_refresh(); } else alert(); } else if (quoted) strcat(prefix, "\""); free(p); } break; case COMMAND: if (c < 0) c = -c - 1; const int a = parse_command_line(key_binding[c], NULL, NULL, false); if (a >= 0) { switch(a) { case LINEUP_A: case LINEDOWN_A: case MOVESOF_A: case MOVEEOF_A: case PAGEUP_A: case PAGEDOWN_A: case NEXTPAGE_A: case PREVPAGE_A: if (history_buff) { switch(a) { case LINEUP_A: line_up(history_buff); break; case LINEDOWN_A: line_down(history_buff); break; case MOVESOF_A: move_to_sof(history_buff); break; case MOVEEOF_A: move_to_bof(history_buff); break; case PAGEUP_A: case PREVPAGE_A: prev_page(history_buff); break; case PAGEDOWN_A: case NEXTPAGE_A: next_page(history_buff); break; } /* In some cases, the default displayed on the command line will be the same as the first history item. In that case we skip it. */ if (first_char_typed == true && a == LINEUP_A && history_buff->cur_line_desc->line && !strncmp(history_buff->cur_line_desc->line, input_buffer, history_buff->cur_line_desc->line_len)) line_up(history_buff); if (history_buff->cur_line_desc->line) { strncpy(input_buffer, history_buff->cur_line_desc->line, min(history_buff->cur_line_desc->line_len,MAX_INPUT_LINE_LEN)); input_buffer[min(history_buff->cur_line_desc->line_len,MAX_INPUT_LINE_LEN)] = 0; len = strlen(input_buffer); encoding = detect_encoding(input_buffer, len); } else { input_buffer[len = 0] = 0; encoding = ENC_ASCII; } x = start_x; pos = 0; offset = 0; input_refresh(); } break; case MOVELEFT_A: input_move_left(true); break; case MOVERIGHT_A: input_move_right(true); break; case BACKSPACE_A: if (pos == 0) break; input_move_left(true); case DELETECHAR_A: if (len > 0 && pos < len) { int c_len = encoding == ENC_UTF8 ? utf8len(input_buffer[pos]) : 1; int c_width = get_char_width(&input_buffer[pos], encoding); memmove(&input_buffer[pos], &input_buffer[pos + c_len], len - pos - c_len + 1); len -= c_len; if (input_buffer_is_ascii()) encoding = ENC_ASCII; if (char_ins_del_ok) { int i, j; move_cursor(ne_lines - 1, x); delete_chars(c_width); for(i = x, j = pos; j < len && i + get_char_width(&input_buffer[j], encoding) < ne_columns - c_width; i += get_char_width(&input_buffer[j], encoding), j = next_pos(input_buffer, j, encoding)); if (j < len) { move_cursor(ne_lines - 1, i); while(j < len && i + get_char_width(&input_buffer[j], encoding) < ne_columns) { output_char(get_char(&input_buffer[j], encoding), 0, encoding); i += get_char_width(&input_buffer[j], encoding); j = next_pos(input_buffer, j, encoding); } } } else input_refresh(); } break; case DELETELINE_A: move_cursor(ne_lines - 1, start_x); clear_to_eol(); input_buffer[len = pos = offset = 0] = 0; encoding = ENC_ASCII; x = start_x; break; case DELETEEOL_A: input_buffer[len = pos] = 0; clear_to_eol(); if (input_buffer_is_ascii()) encoding = ENC_ASCII; break; case MOVEINCUP_A: if (x != start_x) { pos = offset; x = start_x; break; } case MOVESOL_A: input_move_to_sol(); break; case MOVEINCDOWN_A: { int i, j; for(i = x, j = pos; j < len && i + get_char_width(&input_buffer[j], encoding) < ne_columns; i += get_char_width(&input_buffer[j], encoding), j = next_pos(input_buffer, j, encoding)); if (j != pos && j < len) { pos = j; x = i; break; } } case MOVEEOL_A: input_move_to_eol(); break; case TOGGLESEOL_A: case TOGGLESEOF_A: if (pos != 0) input_move_to_sol(); else input_move_to_eol(); break; case PREVWORD_A: input_prev_word(); break; case NEXTWORD_A: input_next_word(); break; case REFRESH_A: input_refresh(); break; case PASTE_A: input_paste(); break; case AUTOCOMPLETE_A: input_autocomplete(); break; case ESCAPE_A: return NULL; default: break; } } break; default: break; } if (selection) { const line_desc * const last = (line_desc *)history_buff->line_desc_list.tail_pred->prev; assert(input_buffer[len] == 0); if (history_buff->num_lines == 0 || len != last->line_len || strncmp(input_buffer, last->line, last->line_len)) add_to_history(input_buffer); return input_buffer; } first_char_typed = false; } }
static void uio_single_step(void *p_handle, os_msg_t *p_msg) { ap_uio_priv_t *p_uio_priv = (ap_uio_priv_t *)p_handle; uio_data_t *p_uio_data = &p_uio_priv->uio_data; event_t evt = {0}; v_key_t key = {0, INVALID_KEY, INVALID_KEY, INVALID_KEY, INVALID_KEY, 0}; static BOOL key_enable = TRUE; static v_key_t last_key = {0, INVALID_KEY, INVALID_KEY, INVALID_KEY, INVALID_KEY, 0}; #ifndef WIN32 chip_ic_t chip_ic_id = hal_get_chip_ic_id(); #else chip_ic_t chip_ic_id = IC_MAGIC; #endif if(p_msg != NULL) { switch(p_msg->content) { case AP_UIO_CMD_FP_DISPLAY: if((p_msg->para2 < 10) && (chip_ic_id == IC_CONCERTO)) { memcpy(p_uio_data->g_led_data,(u8 *)&(p_msg->para1),p_msg->para2); uio_display(p_uio_data->p_dev,(u8 *)p_uio_data->g_led_data, p_msg->para2 + 1); } else { uio_display(p_uio_data->p_dev,(u8 *)&(p_msg->para1), p_msg->para2); } break; case AP_UIO_CMD_ENABLE_IR: key_enable = TRUE; evt.id = UIO_EVT_DISABLE_IR; ap_frm_send_evt_to_ui(APP_UIO, &evt); break; case AP_UIO_CMD_DISABLE_IR: key_enable = FALSE; evt.id = UIO_EVT_ENABLE_IR; ap_frm_send_evt_to_ui(APP_UIO, &evt); break; default: break; } } else { if(get_key_code(p_handle, &key) == TRUE && p_uio_priv->p_impl_info->p_translate_key(&key) == TRUE) { evt.id = UIO_EVT_KEY; evt.data1 = key.v_key; if(key_enable == TRUE) { ap_frm_send_evt_to_ui(APP_UIO, &evt); last_key.v_key = INVALID_KEY; } else { last_key.v_key = key.v_key; } if(key.v_key_2 != INVALID_KEY) { evt.id = UIO_EVT_KEY; evt.data1 = key.v_key_2; key.v_key_2 = INVALID_KEY; ap_frm_send_evt_to_ui(APP_UIO, &evt); } if(key.v_key_3 != INVALID_KEY) { evt.id = UIO_EVT_KEY; evt.data1 = key.v_key_3; key.v_key_3 = INVALID_KEY; ap_frm_send_evt_to_ui(APP_UIO, &evt); } if(key.v_key_4 != INVALID_KEY) { evt.id = UIO_EVT_KEY; evt.data1 = key.v_key_4; key.v_key_4 = INVALID_KEY; ap_frm_send_evt_to_ui(APP_UIO, &evt); } return; } else { if ((last_key.v_key != INVALID_KEY) && (key_enable == TRUE) && (p_uio_priv->p_impl_info->p_translate_key(&key) == TRUE)) { OS_PRINTF("%s,%d,%d\n",__FUNCTION__, __LINE__, last_key.v_key); evt.id = UIO_EVT_KEY; evt.data1 = last_key.v_key; ap_frm_send_evt_to_ui(APP_UIO, &evt); last_key.v_key = INVALID_KEY; } #if 0 //as bianjianjun said,not need. if(mtos_ticks_get() > 5000) { send_one_key(); } #endif } if(p_uio_priv->p_impl_info->p_set_irda_led != NULL) { p_uio_priv->p_impl_info->p_set_irda_led(); } } }
/* If mark_char is not '\0', we bold names ending with it. */ int request_strings(const char * const * const _entries, const int _num_entries, int n, const int _max_name_len, int _mark_char) { action a; input_class ic; int c, i, ne_lines0, ne_columns0; assert(_num_entries > 0); ne_lines0 = ne_columns0 = max_names_per_line = max_names_per_col = x = y = page = 0; entries = _entries; num_entries = _num_entries; max_name_len = _max_name_len + 1; mark_char = _mark_char; while(TRUE) { if (ne_lines0 != ne_lines || ne_columns0 != ne_columns) { if (ne_lines0 && ne_columns0 ) n = PXY2N(page,x,y); if (!(max_names_per_line = ne_columns / (max_name_len))) max_names_per_line = 1; max_names_per_col = ne_lines - 1; names_per_page = max_names_per_line * max_names_per_col; ne_lines0 = ne_lines; ne_columns0 = ne_columns; page = N2P(n); x = N2X(n); y = N2Y(n); print_strings(); print_message(NULL); } move_cursor(y, x * max_name_len); do c = get_key_code(); while((ic = CHAR_CLASS(c)) == IGNORE || ic == INVALID); n = PXY2N(page,x,y); switch(ic) { case ALPHA: if (n >= num_entries) n = num_entries - 1; c = localised_up_case[(unsigned char)c]; for(i = 1; i < num_entries; i++) if (localised_up_case[(unsigned char)entries[(n + i) % num_entries][0]] == c) { normalize((n + i) % num_entries); break; } break; case TAB: if (n >= num_entries) return ERROR; else return -n - 2; case RETURN: if (n >= num_entries) return ERROR; else return n; case COMMAND: if (c < 0) c = -c - 1; if ((a = parse_command_line(key_binding[c], NULL, NULL, FALSE))>=0) { switch(a) { case MOVERIGHT_A: request_move_right(); break; case MOVELEFT_A: request_move_left(); break; case MOVESOL_A: request_move_to_sol(); break; case MOVEEOL_A: request_move_to_eol(); break; case TOGGLESEOL_A: if (x != 0) x = 0; else request_move_to_eol(); break; case LINEUP_A: request_move_up(); break; case LINEDOWN_A: request_move_down(); break; case MOVEINCUP_A: request_move_inc_up(); break; case MOVEINCDOWN_A: request_move_inc_down(); break; case PAGEUP_A: case PREVPAGE_A: request_prev_page(); break; case PAGEDOWN_A: case NEXTPAGE_A: request_next_page(); break; case MOVESOF_A: request_move_to_sof(); break; case MOVEEOF_A: request_move_to_eof(); break; case TOGGLESEOF_A: request_toggle_seof(); break; case ESCAPE_A: return -1; } } break; default: break; } } }
void do_executev (const char *shell, int flags, char *const argv[]) { #ifdef ENABLE_SUBSHELL vfs_path_t *new_dir_vpath = NULL; #endif /* ENABLE_SUBSHELL */ vfs_path_t *old_vfs_dir_vpath = NULL; if (!vfs_current_is_local ()) old_vfs_dir_vpath = vfs_path_clone (vfs_get_raw_current_dir ()); if (mc_global.mc_run_mode == MC_RUN_FULL) save_cwds_stat (); pre_exec (); if (mc_global.tty.console_flag != '\0') handle_console (CONSOLE_RESTORE); if (!mc_global.tty.use_subshell && *argv != NULL && (flags & EXECUTE_INTERNAL) == 0) { printf ("%s%s\n", mc_prompt, *argv); fflush (stdout); } #ifdef ENABLE_SUBSHELL if (mc_global.tty.use_subshell && (flags & EXECUTE_INTERNAL) == 0) { do_update_prompt (); /* We don't care if it died, higher level takes care of this */ invoke_subshell (*argv, VISIBLY, old_vfs_dir_vpath != NULL ? NULL : &new_dir_vpath); } else #endif /* ENABLE_SUBSHELL */ my_systemv_flags (flags, shell, argv); if ((flags & EXECUTE_INTERNAL) == 0) { if ((pause_after_run == pause_always || (pause_after_run == pause_on_dumb_terminals && !mc_global.tty.xterm_flag && mc_global.tty.console_flag == '\0')) && quit == 0 #ifdef ENABLE_SUBSHELL && subshell_state != RUNNING_COMMAND #endif /* ENABLE_SUBSHELL */ ) { printf (_("Press any key to continue...")); fflush (stdout); tty_raw_mode (); get_key_code (0); printf ("\r\n"); fflush (stdout); } if (mc_global.tty.console_flag != '\0' && output_lines != 0 && mc_global.keybar_visible) { putchar ('\n'); fflush (stdout); } } if (mc_global.tty.console_flag != '\0') handle_console (CONSOLE_SAVE); edition_post_exec (); #ifdef ENABLE_SUBSHELL if (new_dir_vpath != NULL) { do_possible_cd (new_dir_vpath); vfs_path_free (new_dir_vpath); } #endif /* ENABLE_SUBSHELL */ if (old_vfs_dir_vpath != NULL) { mc_chdir (old_vfs_dir_vpath); vfs_path_free (old_vfs_dir_vpath); } if (mc_global.mc_run_mode == MC_RUN_FULL) { update_panels (UP_OPTIMIZE, UP_KEEPSEL); update_xterm_title_path (); } do_refresh (); use_dash (TRUE); }
static void do_execute (const char *shell, const char *command, int flags) { #ifdef HAVE_SUBSHELL_SUPPORT char *new_dir = NULL; #endif /* HAVE_SUBSHELL_SUPPORT */ #ifdef USE_VFS char *old_vfs_dir = 0; if (!vfs_current_is_local ()) old_vfs_dir = g_strdup (vfs_get_current_dir ()); #endif /* USE_VFS */ save_cwds_stat (); pre_exec (); if (console_flag) handle_console (CONSOLE_RESTORE); if (!use_subshell && command && !(flags & EXECUTE_INTERNAL)) { printf ("%s%s\n", prompt, command); } #ifdef HAVE_SUBSHELL_SUPPORT if (use_subshell && !(flags & EXECUTE_INTERNAL)) { do_update_prompt (); /* We don't care if it died, higher level takes care of this */ #ifdef USE_VFS invoke_subshell (command, VISIBLY, old_vfs_dir ? 0 : &new_dir); #else invoke_subshell (command, VISIBLY, &new_dir); #endif /* !USE_VFS */ } else #endif /* HAVE_SUBSHELL_SUPPORT */ my_system (flags, shell, command); if (!(flags & EXECUTE_INTERNAL)) { if ((pause_after_run == pause_always || (pause_after_run == pause_on_dumb_terminals && !xterm_flag && !console_flag)) && !quit #ifdef HAVE_SUBSHELL_SUPPORT && subshell_state != RUNNING_COMMAND #endif /* HAVE_SUBSHELL_SUPPORT */ ) { printf (_("Press any key to continue...")); fflush (stdout); mc_raw_mode (); get_key_code (0); printf ("\r\n"); fflush (stdout); } if (console_flag) { if (output_lines && keybar_visible) { putchar ('\n'); fflush (stdout); } } } if (console_flag) handle_console (CONSOLE_SAVE); edition_post_exec (); #ifdef HAVE_SUBSHELL_SUPPORT if (new_dir) do_possible_cd (new_dir); #endif /* HAVE_SUBSHELL_SUPPORT */ #ifdef USE_VFS if (old_vfs_dir) { mc_chdir (old_vfs_dir); g_free (old_vfs_dir); } #endif /* USE_VFS */ update_panels (UP_OPTIMIZE, UP_KEEPSEL); update_xterm_title_path (); do_refresh (); use_dash (TRUE); }
void toggle_panels (void) { #ifdef HAVE_SUBSHELL_SUPPORT char *new_dir = NULL; char **new_dir_p; #endif /* HAVE_SUBSHELL_SUPPORT */ channels_down (); disable_mouse (); if (clear_before_exec) clr_scr (); if (alternate_plus_minus) numeric_keypad_mode (); #ifndef HAVE_SLANG /* With slang we don't want any of this, since there * is no mc_raw_mode supported */ reset_shell_mode (); noecho (); #endif /* !HAVE_SLANG */ keypad (stdscr, FALSE); endwin (); do_exit_ca_mode (); mc_raw_mode (); if (console_flag) handle_console (CONSOLE_RESTORE); #ifdef HAVE_SUBSHELL_SUPPORT if (use_subshell) { new_dir_p = vfs_current_is_local ()? &new_dir : NULL; if (invoke_subshell (NULL, VISIBLY, new_dir_p)) quiet_quit_cmd (); /* User did `exit' or `logout': quit MC quietly */ } else #endif /* HAVE_SUBSHELL_SUPPORT */ { if (output_starts_shell) { fprintf (stderr, _("Type `exit' to return to the Midnight Commander")); fprintf (stderr, "\n\r\n\r"); my_system (EXECUTE_INTERNAL, shell, NULL); } else get_key_code (0); } if (console_flag) handle_console (CONSOLE_SAVE); do_enter_ca_mode (); reset_prog_mode (); keypad (stdscr, TRUE); /* Prevent screen flash when user did 'exit' or 'logout' within subshell */ if (quit) return; enable_mouse (); channels_up (); if (alternate_plus_minus) application_keypad_mode (); #ifdef HAVE_SUBSHELL_SUPPORT if (use_subshell) { load_prompt (0, 0); if (new_dir) do_possible_cd (new_dir); if (console_flag && output_lines) show_console_contents (output_start_y, LINES - keybar_visible - output_lines - 1, LINES - keybar_visible - 1); } #endif /* HAVE_SUBSHELL_SUPPORT */ update_panels (UP_OPTIMIZE, UP_KEEPSEL); update_xterm_title_path (); do_refresh (); }