Example #1
0
 //Keyboard main function
 //Handles all keyboard related tasks
 void keyboard_main( )
 {
	//Update LEDs if USB in use (bluetooth uses different method)
	if(!bluefruit_configured())
		update_leds(keyboard_leds);
	
	uint8_t needs_debounce = 0; // For determining if matrix needs debouncing
	uint16_t matrix_changed = 0;
	matrix_scan();
	// Now that we have scanned the matrix, determine if any actions need to be done
	for (uint8_t row = 0; row < NUMROWS; row++)
	{
		//Check to see if switches in this row has changed
		if ((matrix_changed = matrix_rows[row] ^ matrix_last[row]))
		{
			//At least one switch has changed in this row
			needs_debounce = 1; //We need to debounce
			for (int col = 0; col < NUMCOLS; col++)
			{
				//Find out which columns have changed and act
				if(matrix_changed & ((uint16_t)1<< col))
				{
					//This switch has changed, do whatever the switch was programmed to do
					if(matrix_rows[row] & ((uint16_t)1<< col))
					{
						//Keydown event
						key_execute(get_keycode(row,col),KEY_IS_DOWN);
						//phex(get_keycode(row,col).type);
						//print(":");
						//phex(get_keycode(row,col).code);
						//print(" key is down\n");
					}
					else
					{
						//Keyup event
						key_execute(get_keycode(row,col),KEY_IS_UP);
						//phex(get_keycode(row,col).type);
						//print(":");
						//phex(get_keycode(row,col).code);
						//print(" key is up\n");
					}
					
				}
			}
			matrix_last[row] = matrix_rows[row]; //Row has been dealt with
		}
		else
		{
			//Nothing has changed, do nothing?
		}
	}
	//Allow switch state to stabilize if an edge is detected.
	if (needs_debounce)
		_delay_us(DEBOUNCE_TIME);
 }
Example #2
0
int display_err_msg(int err, char *msg)
{
    struct simple_frame frame;

    memset(&frame, 0, sizeof(frame));

    frame.item_num = 2;
    frame.items[0].pos.row = 1;
    frame.items[0].pos.col = 1;
    strcpy(frame.items[0].title, msg);

    frame.items[1].pos.row = 4;
    frame.items[1].pos.col = 1;
    sprintf(frame.items[1].title, "错误代码:%d", err);
    
    /* for debug */
    printf("err_num:%d", err);
    show_simple_frame(&frame);
    sleep(1);

    clear_cache();
    get_keycode();

    return SUCCESS;
}
Example #3
0
/*
 * ui_get_keycode - get ui keycode 
 *  @key : receive buffer 
 *  @return : status 
 */
int ui_get_keycode(int *key)
{
    int keycode, ime_state;

    ime_state = get_ime_status();
    set_ime_status(INPUT_LOW_CASE);

    clear_cache();
    while (1) {
        keycode = get_keycode();
        if (!(keycode >= '1' && keycode <= '6') && keycode != BACK && keycode != 'z')
            continue;
        else 
            break;
    }

    if (keycode == BACK)
        *key = BACK;
    else if (keycode == 'z')
        *key = HANG;
    else 
        *key = keycode - '0';

    set_ime_status(ime_state);

    return SUCCESS; 
}
Example #4
0
bool speech_dialog::key_press(const SDL_Event& event)
{
	static int last_mouse = 0;
	if(text_char_ == num_chars() && options_.empty() == false) {
		if(event.type == SDL_KEYDOWN) {
			if(event.key.keysym.scancode == get_keycode(controls::CONTROL_UP)) {
				move_up();
			} else if(event.key.keysym.scancode == get_keycode(controls::CONTROL_DOWN)) {
				move_down();
			} else if(event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_SPACE ||
				event.key.keysym.scancode == get_keycode(controls::CONTROL_JUMP) ||
				event.key.keysym.scancode == get_keycode(controls::CONTROL_TONGUE)) {
				return true;
			}
		}
	
#if defined(__ANDROID__)
		// XXX: todo
#elif TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE || TARGET_BLACKBERRY
		if(event.type == SDL_MOUSEBUTTONDOWN)
		{
			last_mouse = event.button.which;
			handle_mouse_move(event.button.x, event.button.y);
		}
		if (event.type == SDL_MOUSEMOTION)
		{
			if (event.motion.which == last_mouse)
				handle_mouse_move(event.motion.x, event.motion.y);
		}
		if (event.type == SDL_MOUSEBUTTONUP)
		{
			if (event.motion.which == last_mouse)
			{
				last_mouse = -1;
				return handle_mouse_move(event.motion.x, event.motion.y);
			}
		}
#endif

		return false;
	} else if (event.type != SDL_KEYDOWN && event.type != SDL_MOUSEBUTTONDOWN) {
		return false; // only keydown and mousebuttondown should be handled by the rest of the function
	}

	return scroll_text();
}
Example #5
0
int display_warn(char *msg)
{
    display_info(msg);

    clear_cache();
    get_keycode();

    return SUCCESS;
}
Example #6
0
/*
 * get_passwd - get string with "*" local echo  
 *
 * @return : status 
 */
int get_passwd(int row, int col, char *password)
{
    int ret;
    int key, offset = 0;
    char ascii_no[USER_PASSWD_LEN + 1] = {0}; 
    char pass_wd[USER_PASSWD_LEN + 1] = {0};

    if (password[0] != '\0') {
        offset = snprintf(ascii_no, USER_PASSWD_LEN + 1, "%s", password);
    }

    ret = SUCCESS;    
    set_ime_status(INPUT_LOW_CASE); 

    clear_cache();
    while (1) {
        show_str(row, col, ascii_no);

        key = get_keycode();
        if (key >= '0' && key <= '9') {
            if (offset < USER_PASSWD_LEN) {
                sprintf(ascii_no + offset, "%c", '*');
                pass_wd[offset] = key;
                offset ++;
            }
        } else {
            switch (key) {
                case ESC:
                   return -EUI_ESC;

                case BACK:
                    if (offset > 0) {
                        ascii_no[offset - 1] = '\0';
                        pass_wd[offset - 1] = '\0';
                        offset --;
                    }
                    break;

                case ENTER:
                    if (offset > 0) {
                        ret = SUCCESS;
                        goto handled;
                    }
                    break;

                default:
                    break;
            }
        }
    }

handled:
    strcpy(password, pass_wd);
    return ret;
}
Example #7
0
File: nilwm.c Project: nqv/nilwm
static
void update_keys_mask() {
    xcb_keycode_t key_num, key_shift, key_caps, key_mode, key;
    xcb_get_modifier_mapping_reply_t *reply;
    xcb_keycode_t *codes;
    unsigned int i, j;

    nil_.mask_numlock    = 0;
    nil_.mask_shiftlock  = 0;
    nil_.mask_capslock   = 0;
    nil_.mask_modeswitch = 0;
    key_num   = get_keycode(XK_Num_Lock);
    key_shift = get_keycode(XK_Shift_Lock);
    key_caps  = get_keycode(XK_Caps_Lock);
    key_mode  = get_keycode(XK_Mode_switch);

    reply = xcb_get_modifier_mapping_reply(nil_.con,
        xcb_get_modifier_mapping_unchecked(nil_.con), 0);
    codes = xcb_get_modifier_mapping_keycodes(reply);

    /* The number of keycodes in the list is 8 * keycodes_per_modifier */
    for (i = 0; i < 8; ++i) {
        for (j = 0; j < reply->keycodes_per_modifier; ++j) {
            key = codes[i * reply->keycodes_per_modifier + j];
            if (!key) {
                continue;
            }
            if (key == key_num) {
                nil_.mask_numlock = (uint16_t)(1 << i);
            } else if (key == key_shift) {
                nil_.mask_shiftlock = (uint16_t)(1 << i);
            } else if (key == key_caps) {
                nil_.mask_capslock = (uint16_t)(1 << i);
            } else if (key == key_mode) {
                nil_.mask_modeswitch = (uint16_t)(1 << i);
            }
        }
    }
    NIL_LOG("mask num=0x%x shift=0x%x caps=0x%x mode=0x%x", nil_.mask_numlock,
        nil_.mask_shiftlock, nil_.mask_capslock, nil_.mask_modeswitch);
    free(reply);
}
Example #8
0
/*
 * get_string - get a string(letter&number) with local echo  
 *
 * @return : status 
 */
int get_string(int row, int col, char *str)
{
    int ret;
    int key, offset = 0;
    char ascii_no[MAX_STR_LEN + 1] = {0}; 

    if (strlen(str) > 0) {
        offset = snprintf(ascii_no, MAX_STR_LEN + 1, "%s", str);
    }

    ret = SUCCESS;
    set_ime_status(INPUT_LOW_CASE); 

    clear_cache();
    while (1) { 
        show_str(row, col, ascii_no);

        key = get_keycode();
        if (islower(key) || (key >= '0' && key <= '9')) {
            if (offset < MAX_STR_LEN) {
                sprintf(ascii_no + offset, "%c", (char)key);
                offset ++;
            }
        } else {
            switch (key) { 
                case ESC:
                    return -EUI_ESC;

                case BACK:
                    if (offset > 0) {
                        ascii_no[offset - 1] = '\0';
                        offset --;
                    }
                    break;

                case ENTER:
                    if (offset > 0) {
                        ret = SUCCESS;
                        goto handled;
                    }
                    break;

                default:
                    break;
            }
        }
    }

handled:
    strcpy(str, ascii_no);
    return ret;
}
Example #9
0
/*
 * question_user - show question and get user option
 *  @return : user option
 */
int question_user(char *title)
{
    int key, ime_state;

    /* 1 : yes, 2: no*/
    int pos = 1, chioce = 1;
    ACTION handle;

    set_questtion_title(title);
    show_current_ui(7);

    lcm_printf(3, 3, "*"); 

    ime_state = get_ime_status();
    set_ime_status(INPUT_FUNC);

    clear_cache();
    while (1) {
        key = get_keycode();
        switch (key) {
            case ENTER:
                handle = get_next_action(7, pos);
                chioce = handle();
                goto handled;
                break;

            case RIGHT:
                if (pos == 1) {
                    lcm_printf(3, 3, " ");
                    lcm_printf(3, 7, "*"); 
                    pos = 2;
                }
                break;

            case LEFT:
                if (pos == 2) {
                    lcm_printf(3, 7, " ");
                    lcm_printf(3, 3, "*");
                    pos = 1;
                }
                break;

            default:
                break;
        }
    } 

handled:
    set_ime_status(ime_state);
    return chioce;
}
Example #10
0
//不会持续扫描键盘缓冲区
void set_buff_tty_normal(TTY *p_tty){
	u8 code;

	code = (u8)get_keycode();

	if(code != NONE){
		/*
		 * 要求缓冲区没有满.
		 */
		if((p_tty -> counter <= TTY_IN_BYTES)){
			p_tty -> buff[p_tty -> head] = (char)code;
			p_tty -> head = (p_tty -> head + 1) % TTY_IN_BYTES;
			p_tty -> counter++;
		}
	}


}
Example #11
0
//不断扫描键盘缓冲区直到有输入为止
void set_buff_tty(TTY *p_tty){
	u8 code;

	while(1){	//must get a scan code

		code = (u8)get_keycode();
		if(code != NONE)
			break;
	}
	/*
	 * 要求缓冲区没有满.
	 */
	if((p_tty -> counter <= TTY_IN_BYTES)){
		p_tty -> buff[p_tty -> head] = (char)code;
		p_tty -> head = (p_tty -> head + 1) % TTY_IN_BYTES;
		p_tty -> counter++;
	}

}
Example #12
0
char get_keycode_ascii(void)
{
	unsigned char code;
	char key;

	code = get_keycode();
	if(code >= 0x80) { /* leave key */
		switch(code - 0x80) {
		case 0x2a: /* left shift */
			keycode.f_keystatus &= (~KEYCODE_STATUS_SHIFT_L);
			break;
		case 0x36:
			keycode.f_keystatus &= (~KEYCODE_STATUS_SHIFT_R);
			break;
		}
		return 0;
	}

	switch(code) {
	case 0x01: /* escape */
		break;
	case 0x2a: /* left shift */
		keycode.f_keystatus |= KEYCODE_STATUS_SHIFT_L;
		break;
	case 0x1d: /* left control */
		break;
	case 0x38: /* left alt */
		break;
	case 0x36: /* right shift */
		keycode.f_keystatus |= KEYCODE_STATUS_SHIFT_R;
		break;
	}
	
	if((keycode.f_keystatus &
		(KEYCODE_STATUS_SHIFT_L | KEYCODE_STATUS_SHIFT_R)) != 0)
	{
		key = keytable_shift[code];
	} else {
		key = keytable[code];
	}

	return key;
}
Example #13
0
File: nilwm.c Project: nqv/nilwm
static
int init_key() {
    unsigned int i;
    const struct key_t *k;
    xcb_keycode_t key;

    nil_.key_syms = xcb_key_symbols_alloc(nil_.con);
    update_keys_mask();

    xcb_ungrab_key(nil_.con, XCB_GRAB_ANY, nil_.scr->root, XCB_MOD_MASK_ANY);
    for (i = 0; i < cfg_.keys_len; ++i) {
        k = &cfg_.keys[i];
        key = get_keycode(k->keysym);
        if (key == 0) {
            continue;
        }
        /* grap key in all combinations of NUMLOCK and CAPSLOCK*/
        GRAB_ALL_MOD_(GRAB_KEY_, nil_.scr->root, key, k->mod);
    }
    return 0;
}
Example #14
0
// returns the keycode of the first key pressed and relased
uint8_t get_key_input(void)
{
	uint8_t keycode_pressed = KC_NO;

	wait_for_all_keys_up();
	wait_for_key_down();

	// scan for the key pressed
	uint8_t row, col;
	for (row = 0; row < NUM_ROWS; ++row)
	{
		for (col = 0; col < NUM_COLS; ++col)
		{
			if (is_pressed_matrix(row, col))
				keycode_pressed = get_keycode(row, col);
		}
	}

	wait_for_all_keys_up();

	return keycode_pressed;
}
Example #15
0
void input_manager::load(const std::string &file_name, bool is_user_preferences)
{
    std::ifstream data_file(file_name.c_str(), std::ifstream::in | std::ifstream::binary);

    if(!data_file.good()) {
        // Only throw if this is the first file to load, that file _must_ exist,
        // otherwise the keybindings can not be read at all.
        if (action_contexts.empty()) {
            throw "Could not read " + file_name;
        }
        return;
    }

    JsonIn jsin(data_file);

    //Crawl through once and create an entry for every definition
    jsin.start_array();
    while (!jsin.end_array()) {
        // JSON object representing the action
        JsonObject action = jsin.get_object();

        const std::string action_id = action.get_string("id");
        const std::string context = action.get_string("category", default_context_id);
        t_actions &actions = action_contexts[context];
        if (!is_user_preferences && action.has_member("name")) {
            // Action names are not user preferences. Some experimental builds
            // post-0.A had written action names into the user preferences
            // config file. Any names that exist in user preferences will be
            // ignored.
            actions[action_id].name = action.get_string("name");
        }

        // Iterate over the bindings JSON array
        JsonArray bindings = action.get_array("bindings");
        t_input_event_list events;
        while (bindings.has_more()) {
            JsonObject keybinding = bindings.next_object();
            std::string input_method = keybinding.get_string("input_method");
            input_event new_event;
            if(input_method == "keyboard") {
                new_event.type = CATA_INPUT_KEYBOARD;
            } else if(input_method == "gamepad") {
                new_event.type = CATA_INPUT_GAMEPAD;
            } else if(input_method == "mouse") {
                new_event.type = CATA_INPUT_MOUSE;
            }

            if (keybinding.has_array("key")) {
                JsonArray keys = keybinding.get_array("key");
                while (keys.has_more()) {
                    new_event.sequence.push_back(
                        get_keycode(keys.next_string())
                    );
                }
            } else { // assume string if not array, and throw if not string
                new_event.sequence.push_back(
                    get_keycode(keybinding.get_string("key"))
                );
            }

            events.push_back(new_event);
        }

        // An invariant of this class is that user-created, local keybindings
        // with an empty set of input_events do not exist in the
        // action_contexts map. In prior versions of this class, this was not
        // true, so users of experimental builds post-0.A will have empty
        // local keybindings saved in their keybindings.json config.
        //
        // To be backwards compatible with keybindings.json from prior
        // experimental builds, we will detect user-created, local keybindings
        // with empty input_events and disregard them. When keybindings are
        // later saved, these remnants won't be saved.
        if (!is_user_preferences ||
            !events.empty() ||
            context == default_context_id ||
            actions.count(action_id) > 0) {
            // In case this is the second file containing user preferences,
            // this replaces the default bindings with the user's preferences.
            action_attributes &attributes = actions[action_id];
            attributes.input_events = events;
            if (action.has_member("is_user_created")) {
                attributes.is_user_created = action.get_bool("is_user_created");
            }
        }
    }
}
Example #16
0
static int
read_config (Display *disp) {
    int ks_per_kk;
    int first_kk, last_kk;
    Atom* syms;

    XDisplayKeycodes (disp, &first_kk, &last_kk);
    syms = XGetKeyboardMapping (disp, first_kk, last_kk - first_kk, &ks_per_kk);
#else
#define ShiftMask       (1<<0)
#define LockMask        (1<<1)
#define ControlMask     (1<<2)
#define Mod1Mask        (1<<3)
#define Mod2Mask        (1<<4)
#define Mod3Mask        (1<<5)
#define Mod4Mask        (1<<6)
#define Mod5Mask        (1<<7)
    int ks_per_kk = -1;
    int first_kk = -1, last_kk = -1;
    int* syms = NULL;
static int
read_config (void) {
#endif
    DB_conf_item_t *item = deadbeef->conf_find ("hotkey.", NULL);
    while (item) {
        if (command_count == MAX_COMMAND_COUNT)
        {
            fprintf (stderr, "hotkeys: maximum number (%d) of commands exceeded\n", MAX_COMMAND_COUNT);
            break;
        }

        command_t *cmd_entry = &commands[ command_count ];
        memset (cmd_entry, 0, sizeof (command_t));

        char token[MAX_TOKEN];
        char keycombo[MAX_TOKEN];
        const char *script = item->value;
        if ((script = gettoken (script, keycombo)) == 0) {
            trace ("hotkeys: unexpected eol (keycombo)\n");
            goto out;
        }
        if ((script = gettoken (script, token)) == 0) {
            trace ("hotkeys: unexpected eol (ctx)\n");
            goto out;
        }
        cmd_entry->ctx = atoi (token);
        if (cmd_entry->ctx < 0 || cmd_entry->ctx >= DDB_ACTION_CTX_COUNT) {
            trace ("hotkeys: invalid ctx %d\n", cmd_entry->ctx);
            goto out;
        }
        if ((script = gettoken (script, token)) == 0) {
            trace ("hotkeys: unexpected eol (isglobal)\n");
            goto out;
        }
        cmd_entry->isglobal = atoi (token);
        if ((script = gettoken (script, token)) == 0) {
            trace ("hotkeys: unexpected eol (action)\n");
            goto out;
        }
        cmd_entry->action = find_action_by_name (token);
        if (!cmd_entry->action) {
            trace ("hotkeys: action not found %s\n", token);
            goto out;
        }

        // parse key combo
        int done = 0;
        char* p;
        char* space = keycombo;
        do {
            p = space;
            space = strchr (p, ' ');
            if (space) {
                *space = 0;
                space++;
            }
            else
                done = 1;

            if (0 == strcasecmp (p, "Ctrl"))
                cmd_entry->modifier |= ControlMask;

            else if (0 == strcasecmp (p, "Alt"))
                cmd_entry->modifier |= Mod1Mask;

            else if (0 == strcasecmp (p, "Shift"))
                cmd_entry->modifier |= ShiftMask;

            else if (0 == strcasecmp (p, "Super")) {
                cmd_entry->modifier |= Mod4Mask;
            }

            else {
                if (p[0] == '0' && p[1] == 'x') {
                    // parse hex keycode
                    int r = sscanf (p, "0x%x", &cmd_entry->keycode);
                    if (!r) {
                        cmd_entry->keycode = 0;
                    }
                }
                else {
                    // lookup name table
                    cmd_entry->keycode = get_keycode (p);
#ifndef NO_XLIB_H
                    cmd_entry->x11_keycode = get_x11_keycode (p, syms, first_kk, last_kk, ks_per_kk);
                    trace ("%s: kc=%d, xkc=%d\n", p, cmd_entry->keycode, cmd_entry->x11_keycode);
#endif
                }
                if (!cmd_entry->keycode)
                {
                    trace ("hotkeys: got 0 from get_keycode while adding hotkey: %s %s\n", item->key, item->value);
                    break;
                }
            }
        } while (!done);

        if (done) {
            if (cmd_entry->keycode == 0) {
                trace ("hotkeys: Key not found while parsing %s %s\n", item->key, item->value);
            }
            else {
                command_count++;
            }
        }
out:
        item = deadbeef->conf_find ("hotkey.", item);
    }
#ifndef NO_XLIB_H
    XFree (syms);
    int i;
    // need to grab it here to prevent gdk_x_error from being called while we're
    // doing it on other thread
    for (i = 0; i < command_count; i++) {
        if (!commands[i].isglobal) {
            continue;
        }
        for (int f = 0; f < 16; f++) {
            uint32_t flags = 0;
            if (f & 1) {
                flags |= LockMask;
            }
            if (f & 2) {
                flags |= Mod2Mask;
            }
            if (f & 4) {
                flags |= Mod3Mask;
            }
            if (f & 8) {
                flags |= Mod5Mask;
            }
            trace ("XGrabKey %d %x\n", commands[i].keycode, commands[i].modifier | flags);
            XGrabKey (disp, commands[i].x11_keycode, commands[i].modifier | flags, DefaultRootWindow (disp), False, GrabModeAsync, GrabModeAsync);
        }
    }
#endif

    return 0;
}
void InputDeviceProvider_X11Keyboard::received_keyboard_input(XKeyEvent &event)
{
    // Is message a down or up event?
    bool keydown;
    if (event.type == KeyPress)
    {
        keydown = true;
    } else	keydown = false;

    InputCode key_code = (InputCode)event.keycode;

    // Prepare event to be emitted:
    InputEvent key;
    if (keydown)
        key.type = InputEvent::pressed;
    else
        key.type = InputEvent::released;

    key.mouse_pos = Pointf(window->get_mouse_position()) / window->get_pixel_ratio();
    key.mouse_device_pos = window->get_mouse_position();

    KeySym key_symbol = XkbKeycodeToKeysym(window->get_display(), key_code, 0, 0);

    bool keypressed = get_keycode(key_symbol);

    // Add to repeat count
    if(keydown && keypressed)
    {
        if( repeat_count.find(key_symbol) == repeat_count.end() )
            repeat_count[key_symbol] = 0;
        else
            repeat_count[key_symbol]++;
    }

    key.repeat_count = repeat_count[key_symbol];

    if( !keydown && !keypressed )
    {
        repeat_count[key_symbol] = -1;

    }

    switch (key_symbol)
    {
    case XK_Control_L:
    case XK_Control_R:
        ctrl_down = keydown;
        break;
    case XK_Shift_L:
    case XK_Shift_R:
        shift_down = keydown;
        break;
    case XK_Alt_L:
    case XK_Alt_R:
        alt_down = keydown;
        break;
    }

    if (event.state & Mod2Mask)	// Num Lock pressed
    {
        switch (key_symbol)
        {
        case XK_KP_Home:
            key_symbol = keycode_numpad7;
            break;
        case XK_KP_Up:
            key_symbol = keycode_numpad8;
            break;
        case XK_KP_Page_Up:
            key_symbol = keycode_numpad9;
            break;
        case XK_KP_Left:
            key_symbol = keycode_numpad4;
            break;
        case XK_KP_Begin:
            key_symbol = keycode_numpad5;
            break;
        case XK_KP_Right:
            key_symbol = keycode_numpad6;
            break;
        case XK_KP_End:
            key_symbol = keycode_numpad1;
            break;
        case XK_KP_Down:
            key_symbol = keycode_numpad2;
            break;
        case XK_KP_Page_Down:
            key_symbol = keycode_numpad3;
            break;
        case XK_KP_Insert:
            key_symbol = keycode_numpad0;
            break;
        case XK_KP_Delete:
            key_symbol = (int) '.';
            break;
        }
    }
    else
    {
        switch (key_symbol)
        {
        case XK_KP_Home:
            key_symbol = keycode_home;
            break;
        case XK_KP_Up:
            key_symbol = keycode_up;
            break;
        case XK_KP_Page_Up:
            key_symbol = keycode_prior;
            break;
        case XK_KP_Left:
            key_symbol = keycode_left;
            break;
        case XK_KP_Begin:
            key_symbol = keycode_clear;
            break;
        case XK_KP_Right:
            key_symbol = keycode_right;
            break;
        case XK_KP_End:
            key_symbol = keycode_end;
            break;
        case XK_KP_Down:
            key_symbol = keycode_down;
            break;
        case XK_KP_Page_Down:
            key_symbol = keycode_next;
            break;
        case XK_KP_Insert:
            key_symbol = keycode_insert;
            break;
        case XK_KP_Delete:
            key_symbol = keycode_delete;
            break;
        }
    }

    key.id = (InputCode)key_symbol;

    key.shift = shift_down;
    key.alt = alt_down;
    key.ctrl = ctrl_down;

    const int buff_size = 16;
    char buff[buff_size];
    int result = XLookupString(&event, buff, buff_size - 1, nullptr, nullptr);
    if (result < 0) result = 0;
    if (result > (buff_size-1)) result = buff_size - 1;
    buff[result] = 0;

    key.str = StringHelp::local8_to_text(std::string(buff, result));

    // Emit message:
    (*sig_provider_event)(key);
}
Example #18
0
/*
 * ui_pinyin - show pinyin spell and corresponding chinese 
 *  @cont : buffer 
 *  @return : one choose chinese 
 */
static int ui_pinyin(char *cont)
{
    int keycode, ime_state, count;
    int pos, page;
    char *chn = NULL;
    char spell[6] = {0};
    char chn_content[CONTENT_SIZE];
    char *ime_pad[] = {
        "        ",  
        "大写数字",
        "小写数字",
        "拼音输入",
        "符号输入"
    };

    ime_state = get_ime_status();
    if (ime_state == INPUT_FUNC) {
        set_ime_status(INPUT_PINYIN);
        ime_state = INPUT_PINYIN;
    }

    show_ime_pad(4, 1, ime_pad[ime_state]);
    clear_cache();

    pos = page = count = 0;
    while (1) {
        keycode = get_keycode();
        switch (keycode) {
            case SHIFT:
                if (ime_state == INPUT_SIGN) 
                    ime_state = INPUT_UP_CASE;
                else 
                    ime_state ++;

                count = 0;
                chn = NULL;    
                memset(spell, 0, 6); 
                memset(chn_content, 0, CONTENT_SIZE);

                /* somewhere blink cursor, concel it */ 
                if (pos > 0) {
                    //set_cursor_off(4, 5 + (pos - 1) * 2);
                    pos = page = 0;
                }
                set_ime_status(ime_state);
                show_str(4, 1, ime_pad[ime_state]);

                break;

            case ESC:
                if (pos > 0) {
                    //set_cursor_off(4, 5 + (pos - 1) * 2);
                    pos = page = 0;
                }

                show_str(4, 1, CHAR_BLANK); 
                return -EUI_ESC;

                break;

            case BACK:
                if (ime_state != INPUT_PINYIN)
                    return -EUI_BACK;

                if (count > 0) {
                    if (pos > 0) {
                        //set_cursor_off(4, 5 + (pos - 1) * 2);
                        pos = page = 0;
                    }

                    spell[--count] = '\0';
                    if (count == 0) {
                        show_str(4, 1, ime_pad[ime_state]);
                        chn = NULL;
                        memset(chn_content, 0, CONTENT_SIZE);
                    } else {
                        show_ime_pad(4, 1, spell);
                        chn = py_ime(spell);
                        if (chn != NULL) {
                            get_chn_pad(chn, chn_content);
                            show_chn_pad(4, 4, chn_content);
                        } else 
                            show_chn_pad(4, 4, NULL);
                    }
                } else {
                    return -EUI_BACK;
                }

                break;

            case ENTER:
                if (count > 0) {
                    if (chn != NULL && pos > 0) {
                        //set_cursor_off(4, 5 + (pos - 1) * 2);
                        pos = page = 0;
                        show_str(4, 1, ime_pad[ime_state]);

                        memcpy(cont, chn + (pos - 1) * 2, 2);
                        goto handled;
                    }
                } else 
                    return ENTER;

                break;
#if 0
            // cursor function error, remove it    
            case LEFT:
                if (chn != NULL) {
                    if (pos > 1) {
                        //set_cursor_off(4, 5 + (pos - 1) * 2);
                        pos --;
                        //set_cursor_on(4, 5 + (pos - 1) * 2);
                    } 
                }

                break;

            case RIGHT:
                if (chn != NULL) {
                    if (pos < 4 && strlen(chn) / 2 > pos){
                        if (pos != 0)
                            //set_cursor_off(4, 5 + (pos - 1) * 2);

                        pos ++;  
                        //set_cursor_off(4, 5 + (pos - 1) * 2);
                    }
                }
                break;
#endif 
            case UP:
                if (chn != NULL) {
                    if (page > 0) {
                        if (pos != 0)
                            //set_cursor_off(4, 5 + (pos - 1) * 2);

                        chn -= 8;
                        get_chn_pad(chn, chn_content);
                        show_chn_pad(4, 4, chn_content);

                        pos = 1;
                        //set_cursor_on(4, 5 + (pos - 1) * 2);
                        page --;
                    }
                }
                break;

            case DOWN:
                if (chn != NULL) {
                    if (strlen(chn) > 8) {
                        if (pos != 0)
                            //set_cursor_off(4, 5 + (pos - 1) * 2);

                        chn += 8;
                        get_chn_pad(chn, chn_content);
                        show_chn_pad(4, 4, chn_content);

                        pos = 1;
                        //set_cursor_on(4, 5 + (pos - 1) * 2);
                        page ++;
                    }
                }
                break;

            default:
                if (ime_state != INPUT_PINYIN) {
                    if (keycode != '\0') {
                        cont[0] = keycode;
                        goto handled;
                    }
                } else {
                    if (islower(keycode)) {
                        if (count < 5) {
                            if (pos > 0) {
                                //set_cursor_off(4, 5 + (pos - 1) * 2);
                                pos = page = 0;
                            }

                            spell[count++] = (char)keycode;
                            show_ime_pad(4, 1, spell);
                            chn = py_ime(spell);
                            if (chn != NULL) {
                                get_chn_pad(chn, chn_content);
                                show_chn_pad(4, 4, chn_content);
                            } else {
                                show_chn_pad(4, 4, NULL);
                            }
                        }
                    }

                    if (isdigit(keycode)) {
                        if (chn != NULL) {
                            if ((keycode - '0') <= (strlen(chn) / 2)) {
                                if (pos > 0) 
                                    //set_cursor_off(4, 5 + (pos - 1) * 2);

                                count = pos = page = 0;
                                memcpy(cont, chn + (keycode - '1') * 2, 2);
                                show_str(4, 1, ime_pad[ime_state]);
                                goto handled;
                            }
                        }
                    }
                }

                break;
        }
    }

handled:
    return SUCCESS;
}
Example #19
0
/*
 * get_hex_num - get hex number
 *  @row, col : local echo position
 *  @pin : receive buffer 
 *  @len : hex number length  
 */
int get_hex_num(int row, int col, uchar *pin, int len)
{
    int i;
    int key, offset = 0;
    char ascii_no[48] = {0}; 

    memset(pin, 0, len);

    set_ime_status(INPUT_LOW_CASE); 

    clear_cache();
    while (1) { 
        show_str(row, col, ascii_no);

        key = get_keycode();
        if ((key >= 'A' && key <= 'F') || (key >= 'a' && key <= 'f') 
                || (key >= '0' && key <= '9')) {
            if (offset < 2*len){
                sprintf(ascii_no + offset, "%c", (char)key);
                offset ++;
            }
        } else {
            switch (key) { 
                case ESC:
                    return -EUI_ESC;

                case BACK:
                    if (offset > 0) {
                        ascii_no[offset - 1] = '\0';
                        offset --;
                    }
                    break;

                case ENTER:
                    if (offset > 0 && offset == 2*len) {
                        goto handled;
                    }
                    break;

                default:
                    break;
            }
        }
    }

handled:
    for (i = 0; i < 2*len; i++) {
        if (ascii_no[i] >= 'A' && ascii_no[i] <= 'F')
            ascii_no[i] = ascii_no[i] - 'A' + 10;
        else if (ascii_no[i] >= 'a' && ascii_no[i] <= 'f')
            ascii_no[i] = ascii_no[i] - 'a' + 10;
        else if (ascii_no[i] >= '0' && ascii_no[i] <= '9')
            ascii_no[i] = ascii_no[i] - '0';
    }

    for (i = 0; i < len; i++) {
        pin[i] = ascii_no[2 * i] * 16 + ascii_no[2*i + 1];
    }

    return SUCCESS;
}
Example #20
0
int get_inter_num(int row, int col, int *num)
{
    int ret;
    int key, offset = 0;

    /* max : 0 - 10000 */
    char ascii_no[6] = {0}; 

    if (*num != 0) {
        offset = snprintf(ascii_no, 5, "%d", *num);
    } 

    ret = SUCCESS;    
    set_ime_status(INPUT_LOW_CASE);

    clear_cache();
    while (1) {
        show_inter_num(row, col, ascii_no);

        key = get_keycode();
        if (isdigit(key)) {
            if (offset < 5) {
                sprintf(ascii_no + offset, "%c", (char)key);
                offset ++;
            }
        } else {
            switch (key) {
                case D_ZERO:
                    if (offset != 0 && offset < 4) {
                        sprintf(ascii_no + offset, "%c%c", '0', '0');
                        offset += 2;
                    } else {
                        if (offset == 4) {
                            sprintf(ascii_no + offset, "%c", '0');
                            offset ++;
                        }
                    }
                    break;

                case BACK:
                    if (offset > 0) {
                        ascii_no[offset - 1] = '\0';
                        offset --;
                    }
                    break;

                case ESC:
                    return -EUI_ESC;
                    goto handled;
                    break;

                case ENTER:
                    ret = SUCCESS;
                    goto handled;
                    break;

                default:
                    break;
            }
        }
    }

handled:
    *num = atoi(ascii_no);

    return ret;
}
Example #21
0
/*
 * get_bcd_date - get bcd format date and echo local 
 *  @row, col : local echo position 
 *  @bcd_date : the getting date  
 */
int get_bcd_date(int row, int col, struct bcd_date * enddate)
{
    int ret;
    int key, offset = 0;
    uint y, m, d;
    char year[4 + 1] = {0}, mon[2 + 1] = {0}, day[2 + 1] = {0};
    char ascii_no[9] = {0}; 
    
    bcd_to_greg(enddate, &y, &m, &d);
    if (y != 0 || m != 0 || d != 0) {
        offset = snprintf(ascii_no, 9, "%d%02d%02d", y, m, d);
    } 

    ret = SUCCESS; 
    set_ime_status(INPUT_LOW_CASE); 

    clear_cache();
    while (1) {
        show_str(row, col, ascii_no);

        key = get_keycode();
        if (isdigit(key)) {
            if (offset < 8) {
                sprintf(ascii_no + offset, "%c", (char)key);
                offset ++;
            }
        } else {
            switch (key) {
                case BACK:
                    if (offset > 0) {
                        ascii_no[offset - 1] = '\0';
                        offset --;
                    }
                    break;

                case ESC:
                    ret = -EUI_ESC;
                    goto handled;
                    break;

                case ENTER:
                    if (offset > 0) {
                        ret = SUCCESS;
                        goto handled;
                    }
                    break;

                default:
                    break;
            }
        }
    }

handled:
    if (ret == -EUI_ESC) 
        return ret;

    memcpy(year, ascii_no, 4);
    memcpy(mon, ascii_no + 4, 2);
    memcpy(day, ascii_no + 6, 2);
    y = m = d = 0;

    y = atoi(year);
    m = atoi(mon);
    d = atoi(day);

    if (y >= 2014 && y <= 2100 && m > 0 && m <= 12 && d > 0 && d <= 31) {
        greg_to_bcd(enddate, y, m, d);
    } else {
        ret = -EUI_BAD_DATE_FORMAT;
    }

    return ret;
}
Example #22
0
int get_greg_time(int row, int col, struct greg_time *time)
{
    int ret;
    int key, offset = 0;
    char hour[2 + 1] = {0}, min[2 + 1] = {0}, sec[2 + 1] = {0};
    char ascii_no[7] = {0}; 

    if (time->hour != 0 || time->min != 0 || time->sec != 0) {
        offset = snprintf(ascii_no, 7, "%02d%02d%02d", 
                time->hour, time->min, time->sec);
    }

    ret = SUCCESS;    
    set_ime_status(INPUT_LOW_CASE); 

    clear_cache();
    while (1) {
        show_str(row, col, ascii_no);

        key = get_keycode();
        if (isdigit(key)) {
            if (offset < 6) {
                sprintf(ascii_no + offset, "%c", (char)key);
                offset ++;
            }
        } else {
            switch (key) {
                case BACK:
                    if (offset > 0) {
                        ascii_no[offset - 1] = '\0';
                        offset --;
                    }
                    break;

                case ESC:
                    ret = -EUI_ESC;
                    goto handled;
                    break;

                case ENTER:
                    if (offset > 0) {
                        ret = SUCCESS;
                        goto handled;
                    }
                    break;

                default:
                    break;
            }
        }
    }

handled:
    if (ret == -EUI_ESC)
        return ret;

    memcpy(hour, ascii_no, 2);
    memcpy(min, ascii_no + 2, 2);
    memcpy(sec, ascii_no + 4, 2);

    time->hour = time->min = time->sec = 0;

    time->hour = atoi(hour);
    time->min = atoi(min);
    time->sec = atoi(sec);

    if (time->hour >= 0 && time->hour <= 23 
            && time->min >= 0 && time->min <= 59 
            && time->sec >= 0 && time->sec <= 59) {

        ret = SUCCESS;
    } else {
        ret = -EUI_BAD_TIME_FORMAT;
    }

    return ret;
}
Example #23
0
void input_manager::init()
{
    init_keycode_mapping();

    std::ifstream data_file;

    std::string file_name = "data/raw/keybindings.json";
    data_file.open(file_name.c_str(), std::ifstream::in | std::ifstream::binary);

    if(!data_file.good()) {
        throw "Could not read " + file_name;
    }

    JsonIn jsin(data_file);

    //Crawl through once and create an entry for every definition
    jsin.start_array();
    while (!jsin.end_array()) {
        // JSON object representing the action
        JsonObject action = jsin.get_object();

        const std::string action_id = action.get_string("id");
        actionID_to_name[action_id] = action.get_string("name", action_id);
        const std::string context = action.get_string("category", "default");

        // Iterate over the bindings JSON array
        JsonArray bindings = action.get_array("bindings");
        const bool defaultcontext = (context == "default");
        while (bindings.has_more()) {
            JsonObject keybinding = bindings.next_object();
            std::string input_method = keybinding.get_string("input_method");
            input_event new_event;
            if(input_method == "keyboard") {
                new_event.type = CATA_INPUT_KEYBOARD;
            } else if(input_method == "gamepad") {
                new_event.type = CATA_INPUT_GAMEPAD;
            } else if(input_method == "mouse") {
                new_event.type = CATA_INPUT_MOUSE;
            }

            if (keybinding.has_array("key")) {
                JsonArray keys = keybinding.get_array("key");
                while (keys.has_more()) {
                    new_event.sequence.push_back(
                        get_keycode(keys.next_string())
                    );
                }
            } else { // assume string if not array, and throw if not string
                new_event.sequence.push_back(
                    get_keycode(keybinding.get_string("key"))
                );
            }

            if (defaultcontext) {
                action_to_input[action_id].push_back(new_event);
            } else {
                action_contexts[context][action_id].push_back(new_event);
            }
        }
    }

    data_file.close();
}
Example #24
0
static int
read_config (Display *disp)
{
    int ks_per_kk;
    int first_kk, last_kk;
    KeySym* syms;

    XDisplayKeycodes (disp, &first_kk, &last_kk);
    syms = XGetKeyboardMapping (disp, first_kk, last_kk - first_kk, &ks_per_kk);

    DB_conf_item_t *item = deadbeef->conf_find ("hotkeys.", NULL);
    while (item) {
        if (command_count == MAX_COMMAND_COUNT)
        {
            fprintf (stderr, "hotkeys: maximum number (%d) of commands exceeded\n", MAX_COMMAND_COUNT);
            break;
        }

        command_t *cmd_entry = &commands[ command_count ];
        cmd_entry->modifier = 0;
        cmd_entry->keycode = 0;

        size_t l = strlen (item->value);
        char param[l+1];
        memcpy (param, item->value, l+1);
        
        char* colon = strchr (param, ':');
        if (!colon)
        {
            fprintf (stderr, "hotkeys: bad config option %s %s\n", item->key, item->value);
            continue;
        }
        char* command = colon+1;
        *colon = 0;

        int done = 0;
        char* p;
        char* space = param - 1;
        do {
            p = space+1;
            space = strchr (p, ' ');
            if (space)
                *space = 0;
            else
                done = 1;

            if (0 == strcasecmp (p, "Ctrl"))
                cmd_entry->modifier |= ControlMask;

            else if (0 == strcasecmp (p, "Alt"))
                cmd_entry->modifier |= Mod1Mask;

            else if (0 == strcasecmp (p, "Shift"))
                cmd_entry->modifier |= ShiftMask;

            else if (0 == strcasecmp (p, "Super")) {
                cmd_entry->modifier |= Mod4Mask;
            }

            else {
                if (p[0] == '0' && p[1] == 'x') {
                    // parse hex keycode
                    int r = sscanf (p, "0x%x", &cmd_entry->keycode);
                    if (!r) {
                        cmd_entry->keycode = 0;
                    }
                }
                else {
                    // lookup name table
                    cmd_entry->keycode = get_keycode (disp, p, syms, first_kk, last_kk, ks_per_kk);
                }
                if (!cmd_entry->keycode)
                {
                    trace ("hotkeys: got 0 from get_keycode while adding hotkey: %s %s\n", item->key, item->value);
                    break;
                }
            }
        } while (!done);

        if (done) {
            if (cmd_entry->keycode == 0) {
                trace ("hotkeys: Key not found while parsing %s %s\n", item->key, item->value);
            }
            else {
                command = trim (command);
                cmd_entry->action = get_action (command);
                if (!cmd_entry->action)
                {
                    trace ("hotkeys: Unknown command <%s> while parsing %s %s\n", command,  item->key, item->value);
                }
                else {
                    command_count++;
                }
            }
        }
        item = deadbeef->conf_find ("hotkeys.", item);
    }
    XFree (syms);
    int i;
    // need to grab it here to prevent gdk_x_error from being called while we're
    // doing it on other thread
    for (i = 0; i < command_count; i++) {
        for (int f = 0; f < 16; f++) {
            uint32_t flags = 0;
            if (f & 1) {
                flags |= LockMask;
            }
            if (f & 2) {
                flags |= Mod2Mask;
            }
            if (f & 4) {
                flags |= Mod3Mask;
            }
            if (f & 8) {
                flags |= Mod5Mask;
            }
            XGrabKey (disp, commands[i].keycode, commands[i].modifier | flags, DefaultRootWindow (disp), False, GrabModeAsync, GrabModeAsync);
        }
    }

    return 0;
}