Esempio n. 1
0
/* 
	Our window with cursor has got some input
	
	key_cnt == -1 means no input has been taking place at this cursor position
	key_cnt >= 0 means the same key has been pressed one or more times here
*/
void
win_cursor_input(int new_key){
	char c;
	
	if (new_key == CURSOR_LEFT){
		dec_cursor();
		key_cnt = -1;
		last_key = -1;
		timer_stop(&char_tmr);
		return;
	};
	
	if (new_key == CURSOR_RIGHT){
		advance_cursor();
		key_cnt = -1;
		last_key = -1;
		timer_stop(&char_tmr);
		return;
	};
	
	/* A bit tricky. It makes sense to implement this as a kind of delete, i.e. delete the character 
		under the cursor. This only fails if the cursor is at end of text. Then delete the last character.
	*/
	if (new_key == CURSOR_BACKSPACE){
		key_cnt = -1;
		last_key = -1;
		timer_stop(&char_tmr);
		
		del_char(pcursor_win, cursor_pos);
		cursor_pos = min(cursor_pos, pcursor_win->text_len);
		return;	
	};
	
	timer_set(&char_tmr, WAIT_KEY_TIME, 0);				// start auto advance timer	
	/* This is the first time a key is pressed here */
	if (key_cnt < 0){
		key_cnt = 0;
		c = key2char(new_key, 0);
		store_char(pcursor_win, cursor_pos, c);
	} else {
		/* We already entered text at this cursor position */	
		if (new_key == last_key){			// User pressed the same key twice before a time out occured 
			key_cnt++;
			c = key2char(new_key, key_cnt);
			store_char(pcursor_win, cursor_pos, c);
		} else {
		// User pressed a different key, advance to the next cursor position, store new char
			key_cnt = 0;
			c = key2char(new_key, 0);
			advance_cursor();
			store_char(pcursor_win, cursor_pos, c);
		};
	};
	last_key = new_key;		
};
Esempio n. 2
0
/*---------------------------------------------------------------------*/
void update_console()
{
    update_widget_all( &cons, &t_state );

    u8 code = 0;
    u32 addr = 0;
    u32 id = 0;
    {
        code = dequeue( &key_queue );
        if( code != 0 ) {
            if( code == _KEY_HANKAKU_ZENKAKU_PRESSED ) {
                __key_ptr = __key_ptr == __key1 ? __key2 : __key1;
            } else if( is_valid_key(code) || code == _KEY_ENTER_RELEASED || code == _KEY_SPACE_RELEASED ) {
                if( is_valid_key(code) ) {
                    code = key2char( code );
                    putc_console( code );
                } else if( code == _KEY_ENTER_RELEASED ) {
                    putc_console( '\n' );
                } else if( code == _KEY_SPACE_RELEASED ) {
                    code = ' ';
                    putc_console( code );
                }
                enqueue( &cmd_queue, code );
            }
        }
        cmd_parsing();

        get_timer( &l_time );
        putn_col( l_time.tick, 8*15, 16*3, 10 );
    }
}