예제 #1
0
static void type_keystroke( ChewingContext *ctx, get_char_func get_char, void *param )
{
	int ch;

	while ( ( ch = get_keystroke( get_char, param ) ) != END )
		type_single_keystroke( ctx, ch );
}
예제 #2
0
/* DDS3.2.6: Interpret Keystroke */
enum input_event interpret_keystroke(void)
{
	enum input_event key;

	key = get_keystroke();

	if (key == INPUT_UP
	    || key == INPUT_DOWN
	    || key == INPUT_NEXT
	    || key == INPUT_PREVIOUS
	    || key == INPUT_UNDO
	    || key == INPUT_SELECT)
		store_keystroke(key);

	return key;
}
예제 #3
0
int main(int argc, char *argv[])
{
    ChewingContext *ctx;
    int i;
    FILE *fp = stdin;

    /* Initialize libchewing */
    putenv("CHEWING_PATH=" CHEWING_DATA_PREFIX);
    /* for the sake of testing, we should not change existing hash data */
    putenv("CHEWING_USER_PATH=" TEST_HASH_DIR);

    if (argc == 2) {
        fp = fopen(argv[1], "r");
        if (!fp) {
            fprintf(stderr, "failed to open '%s'\n", argv[1]);
            return 1;
        }
    }

    /* Request handle to ChewingContext */
    ctx = chewing_new();

    /* Set keyboard type */
    chewing_set_KBType(ctx, chewing_KBStr2Num("KB_DEFAULT"));

    chewing_set_candPerPage(ctx, 9);
    chewing_set_maxChiSymbolLen(ctx, 16);
    chewing_set_addPhraseDirection(ctx, 1);
    chewing_set_selKey(ctx, selKey_define, 10);
    chewing_set_spaceAsSelection(ctx, 1);

    while (1) {
        i = get_keystroke(get_char_from_fp, fp);
        if (i == END)
            goto end;
        type_single_keystroke(ctx, i);
        commit_string(ctx);
    }
  end:
    /* Free Chewing IM handle */
    chewing_delete(ctx);
    if (fp)
        fclose(fp);

    return 0;
}
예제 #4
0
/**
 * Waits (sleeps) for the given number of ticks.
 * Checks for keystroke.
 *
 * @returns BIOS scan code if available, 0 if not.
 * @param   ticks       Number of ticks to sleep.
 * @param   stop_on_key Whether to stop immediately upon keypress.
 */
uint8_t wait(uint16_t ticks, uint8_t stop_on_key)
{
    long        ticks_to_wait, delta;
    uint16_t    old_flags;
    uint32_t    prev_ticks, t;
    uint8_t     scan_code = 0;

    /*
     * We may or may not be called with interrupts disabled. For the duration
     * of this function, interrupts must be enabled.
     */
    old_flags = int_query();
    int_enable();

    /*
     * The 0:046c wraps around at 'midnight' according to a 18.2Hz clock.
     * We also have to be careful about interrupt storms.
     */
    ticks_to_wait = ticks;
    prev_ticks = read_dword(0x0, 0x46c);
    do
    {
        halt();
        t = read_dword(0x0, 0x46c);
        if (t > prev_ticks)
        {
            delta = t - prev_ticks;     /* The temp var is required or bcc screws up. */
            ticks_to_wait -= delta;
        }
        else if (t < prev_ticks)
            ticks_to_wait -= t;         /* wrapped */
        prev_ticks = t;

        if (check_for_keystroke())
        {
            scan_code = get_keystroke();
            bios_printf(BIOS_PRINTF_INFO, "Key pressed: %x\n", scan_code);
            if (stop_on_key)
                return scan_code;
        }
    } while (ticks_to_wait > 0);
    int_restore(old_flags);
    return scan_code;
}
예제 #5
0
파일: RUN.C 프로젝트: PrincipiaCollege/RSC
int get_speed(enum speed *run_speed) {
  char choice;
  int return_val;

  gotoxy(10,23);
  delline();
  cprintf("Run Speed: Cycle, Slow, or Fast (C/S/F) ");
  choice = toupper(get_keystroke());

  if(choice == EscKey) {
    return_val = STOP;
  } else {
    switch(choice) {
      case 'S':
        *run_speed = SLOW;
        return_val = CONTINUE;
        break;

      case 'F':
        *run_speed = FAST;
        return_val = CONTINUE;
        break;

      case 'C':
        *run_speed = CYCLE;
        return_val = CONTINUE;
        break;

      default:
        return_val = STOP;
    }
  }

  delline();
  return return_val;
}
예제 #6
0
int main( int argc, char *argv[] )
#endif
{
	ChewingContext *ctx;
	char *prefix = CHEWING_DATA_PREFIX;
	int i;
	int ctrl_shifted;

	/* Initialize libchewing */
	/* for the sake of testing, we should not change existing hash data */
	chewing_Init( prefix, TEST_HASH_DIR );

	/* Request handle to ChewingContext */
	ctx = chewing_new();

	/* Set keyboard type */ 
	chewing_set_KBType( ctx, chewing_KBStr2Num( "KB_DEFAULT" ) );

	chewing_set_candPerPage( ctx, 9 );
	chewing_set_maxChiSymbolLen( ctx, 16 );
	chewing_set_addPhraseDirection( ctx, 1 );
	chewing_set_selKey( ctx, selKey_define, 10 );
	chewing_set_spaceAsSelection( ctx, 1 );

	while ( 1 ) {
		i = get_keystroke();
		switch ( i ) {
			case KEY_LEFT:
				chewing_handle_Left( ctx );
				break;
			case KEY_SLEFT:
				chewing_handle_ShiftLeft( ctx );
				break;
			case KEY_RIGHT:
				chewing_handle_Right( ctx );
				break;
			case KEY_SRIGHT:
				chewing_handle_ShiftRight( ctx );
				break;
			case KEY_UP:
				chewing_handle_Up( ctx );
				break;
			case KEY_DOWN:
				chewing_handle_Down( ctx );
				break;
			case KEY_SPACE:
				chewing_handle_Space( ctx );
				break;
			case KEY_ENTER:
				chewing_handle_Enter( ctx );
				break;
			case KEY_BACKSPACE:
				chewing_handle_Backspace( ctx );
				break;
			case KEY_ESC:
				chewing_handle_Esc( ctx );
				break;
			case KEY_DELETE:
				chewing_handle_Del( ctx );
				break;
			case KEY_HOME:
				chewing_handle_Home( ctx );
				break;
			case KEY_END:
				chewing_handle_End( ctx );
				break;
			case KEY_TAB:
				chewing_handle_Tab( ctx );
				break;			
			case KEY_CAPSLOCK:
				chewing_handle_Capslock( ctx );
				break;
			case END:
				goto end;
			default:
				ctrl_shifted = ( i - KEY_CTRL_BASE );
				if ( ( ctrl_shifted >= '0' ) && ( ctrl_shifted <= '9' ) ) {
					chewing_handle_CtrlNum( ctx, ctrl_shifted );
				} else {
					chewing_handle_Default( ctx, (char) i );
				}
				break;
		}
		commit_string( ctx );
#ifdef USED_IN_SIMULATION
		if ( i == KEY_ENTER )
			compare_per_run();
#endif
	}
end:
	/* Free Chewing IM handle */
	chewing_delete( ctx );
	
	/* Termate Chewing services */
	chewing_Terminate();
#ifndef USED_IN_SIMULATION
	printf( "\n" );
#endif
	return 0;
}