コード例 #1
0
ファイル: keyboard.c プロジェクト: mjwoodcock/sdl-asylum
int read_key()
{
    update_keyboard();
    int key = keybuf;
    keybuf = -1;
    return key;
}
コード例 #2
0
ファイル: keyboard.c プロジェクト: mjwoodcock/sdl-asylum
int read_key_unicode()
{
    update_keyboard();
    int uni = unibuf;
    unibuf = -1;
    return uni;
}
コード例 #3
0
void KEYBOARD::write_signal(int id, uint32_t data, uint32_t mask)
{
	if(column != (data & mask)) {
		column = data & mask;
		update_keyboard();
	}
}
コード例 #4
0
DEFINE_THREAD_ROUTINE(KeyboardController, data)
{
  init_keyboard();
  update_keyboard();
  close_keyboard();  
  return (THREAD_RET) 0;

}
コード例 #5
0
void KEYBOARD::event_frame()
{
	bool new_pressed = (key_stat[0x13] != 0);
	if(new_pressed && !break_pressed) {
		d_cpu->write_signal(SIG_CPU_NMI, 1, 1);
	}
	break_pressed = new_pressed;
	
	update_keyboard();
}
コード例 #6
0
ファイル: keyboard.c プロジェクト: mjwoodcock/sdl-asylum
int read_key_greater_than_15()
{
    int retval;

    update_keyboard();
    if (keybuf < 16)
        retval = -1;
    else
        retval = keybuf;
    keybuf = -1;
    return retval;
}
コード例 #7
0
ファイル: editor.cpp プロジェクト: ChristophKuhfuss/supertux
void Editor::update(float elapsed_time)
{
  // Pass all requests
  if (reload_request) {
    reload_level();
  }

  if (quit_request) {
    quit_editor();
  }

  if (newlevel_request) {
    //Create new level
  }

  if (reactivate_request) {
    enabled = true;
    reactivate_request = false;
  }

  if (save_request) {
    level->save(world ? FileSystem::join(world->get_basedir(), levelfile) :
                         levelfile);
    enabled = true;
    save_request = false;
  }

  if (test_request) {
    test_request = false;
    MouseCursor::current()->set_icon(NULL);
    test_level();
    return;
  }

  if (deactivate_request) {
    enabled = false;
    deactivate_request = false;
    return;
  }

  // update other stuff
  if (is_active()) {
    currentsector->update(0);
    tileselect.update(elapsed_time);
    layerselect.update(elapsed_time);
    inputcenter.update(elapsed_time);
    scroller.update(elapsed_time);
    update_keyboard();
  }
}
コード例 #8
0
ファイル: main.cpp プロジェクト: bothemasterofall/bayou
int main()
{
    //shell vars
    bool render = false;

    //allegro vars
    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    ALLEGRO_TIMER *timer = NULL;

    //allegro init functions
    printf ("Initializing allegro\n");
    if (!al_init())
    {
        al_show_native_message_box(NULL, NULL, NULL, "failed", NULL, 0);
        return -1;
    }

    printf("Creating display\n");
    display = al_create_display(WIDTH, HEIGHT);
    if (!display)
    {
        al_show_native_message_box(NULL, NULL, NULL, "failed", NULL, 0);
        return -1;
    }

    printf("Installing addons\n");
    al_init_font_addon();
    al_init_ttf_addon();
    al_init_primitives_addon();
    al_init_image_addon();
    al_install_keyboard();
    al_install_mouse();
    al_install_audio();
    al_init_acodec_addon();
    al_reserve_samples(10);

    //project inits
    srand(time(NULL));

    printf("Initializing timer\n");
    event_queue = al_create_event_queue();
    timer = al_create_timer(1.0 / FPS);

    printf("Registering event sources\n");
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_start_timer(timer);

    printf("Init mouse and keyboard\n");
    init_keyboard();
    init_mouse();

    printf("Loading assets\n");
    load_bitmaps();
    load_fonts();
    load_samples();

    printf ("Creating manager\n");
    push_state(new TitleMenu());
    
    printf("Beginning game\n");
    while (!is_game_over())
    {
        //declare an event
        ALLEGRO_EVENT event;

        //monitor event sources
        al_wait_for_event(event_queue, &event);
        if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
        {
            end_game();
        }
        else if (event.type == ALLEGRO_EVENT_TIMER)
        {
            render = true;

            update_mouse();
            update_keyboard();

            handle_key();
            update_game();
        }

        // Render screen
        if (render && al_event_queue_is_empty(event_queue))
        {
            render = false;
            render_game();
            al_flip_display();
        }
    }

    unload_assets();
    al_destroy_event_queue(event_queue);
    al_destroy_display(display);
    al_destroy_timer(timer);

    return 0;
}
コード例 #9
0
ファイル: driver.cpp プロジェクト: sunsuri/crostrackpad2
void TrackpadRawInput(PDEVICE_CONTEXT pDevice, struct cyapa_softc *sc, struct cyapa_regs *regs, int tickinc){
	int nfingers;
	int afingers;	/* actual fingers after culling */
	int i;

	nfingers = CYAPA_FNGR_NUMFINGERS(regs->fngr);
	afingers = nfingers;

	//	system("cls");
#ifdef DEBUG
	CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "stat %02x\tTracking ID: %d\tbuttons %c%c%c\tnfngrs=%d\n",
		regs->stat,
		regs->touch->id,
		((regs->fngr & CYAPA_FNGR_LEFT) ? 'L' : '-'),
		((regs->fngr & CYAPA_FNGR_MIDDLE) ? 'M' : '-'),
		((regs->fngr & CYAPA_FNGR_RIGHT) ? 'R' : '-'),
		nfingers
		);
#endif

	for (i = 0; i < nfingers; ++i) {
#ifdef DEBUG
		CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, " [x=%04d y=%04d p=%d]\n",
			CYAPA_TOUCH_X(regs, i),
			CYAPA_TOUCH_Y(regs, i),
			CYAPA_TOUCH_P(regs, i));
		if (CYAPA_TOUCH_Y(regs, i) > 400){
			if (CYAPA_TOUCH_X(regs, i) < 400){
				CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "Simulate left hardware button! %d\n", CYAPA_TOUCH_Y(regs, i));
			}
			else {
				CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "Simulate right hardware button! %d\n", CYAPA_TOUCH_Y(regs, i));
			}
		}
#endif
		if (CYAPA_TOUCH_P(regs, i) < cyapa_minpressure)
			--afingers;
	}

	if (regs->touch->id != sc->lastid){
		sc->x = 0;
		sc->y = 0;
		sc->lastid = regs->touch->id;
	}

	int x = sc->x;
	int y = sc->y;

	bool overrideDeltas = false;

	if (afingers > 0){
#ifdef DEBUG
		CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "Tick inc.\n");
#endif
		sc->tick += tickinc;
		x = CYAPA_TOUCH_X(regs, 0);
		y = CYAPA_TOUCH_Y(regs, 0);
		if (afingers > 1){
			int x1 = CYAPA_TOUCH_X(regs, 0);
			int y1 = CYAPA_TOUCH_Y(regs, 0);
			int x2 = CYAPA_TOUCH_X(regs, 1);
			int y2 = CYAPA_TOUCH_Y(regs, 1);

			int d1 = distancesq(x1 - sc->x, y1 - sc->y);
			int d2 = distancesq(x1 - sc->x, y1 - sc->y);
			if (d2 < d1 || (y > 400 && y2 < 400)){
				x = x2;
				y = y2;
			}
#ifdef DEBUG
			CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "%d %d\t%d %d\t%d %d\n", x, y, x1, y1, x2, y2);
#endif
		}
		else {
			if (sc->mousedown && y > 400){
				overrideDeltas = true;
				sc->x = 0;
				sc->y = 0;
			}
		}
		if ((overrideDeltas != true) && (sc->x == 0 && sc->y == 0)){
			sc->x = x;
			sc->y = y;
		}
	}
	else {
		if (sc->tick < 10 && sc->tick != 0){
			INPUT input;
			if (sc->lastnfingers == 1){
				sc->mousebutton = 0;
			}
			else if (sc->lastnfingers == 2){
				sc->mousebutton = 1;
			}
			else if (sc->lastnfingers == 3){
				sc->mousebutton = 2;
			}
			else if (sc->lastnfingers == 4){
				sc->mousebutton = 3;
			}
			input.mi.dx = 0;
			input.mi.dy = 0;
			input.mi.mouseData = 0;
			sc->mousedown = true;
			MySendInput(pDevice, &input, sc);
			sc->tickssincelastclick = 0;
#ifdef DEBUG
			CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "Tap to Click!\n");
#endif
		}
		sc->tick = 0;
		sc->hasmoved = false;
		sc->mousedownfromtap = false;
		sc->tickssincelastclick+=tickinc;
#ifdef DEBUG
		CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "Move Reset!\n");
#endif
	}

	int delta_x = x - sc->x, delta_y = y - sc->y;
	if (abs(delta_x) + abs(delta_y) > 10 && !sc->hasmoved){
		sc->hasmoved = true;
		if (sc->tickssincelastclick < 10 && sc->tickssincelastclick >= 0){
			INPUT input;
			input.mi.dx = 0;
			input.mi.dy = 0;
			input.mi.mouseData = 0;
			MySendInput(pDevice, &input, sc);
			sc->mousebutton = 0;
			sc->mousedown = true;
			sc->mousedownfromtap = true;
			sc->tickssincelastclick = 0;
#ifdef DEBUG
			CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "Move from tap!\n");
#endif
		}
#ifdef DEBUG
		CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "Has moved!\n");
#endif
	}
	if (overrideDeltas){
		delta_x = 0;
		delta_y = 0;
	}

	sc->lastnfingers = nfingers;

	if (CYAPA_TOUCH_P(regs, 0) < 20)
		sc->tick -= tickinc;
	if (CYAPA_TOUCH_P(regs, 0) < 10)
		sc->tick = 0;
	else if (sc->hasmoved)
		sc->tick = 0;
	if (sc->tick < 0)
		sc->tick = 0;

	INPUT input;
	if (afingers < 2 || sc->mousedown){
		input.mi.dx = (BYTE)delta_x;
		input.mi.dy = (BYTE)delta_y;
		input.mi.dwFlags = MOUSEEVENTF_MOVE;
		if (delta_x != 0 && delta_y != 0)
			MySendInput(pDevice, &input, sc);
	}
	else if (afingers == 2){
		if (abs(delta_x) > abs(delta_y)){
			input.mi.dwFlags = MOUSEEVENTF_HWHEEL;
			input.mi.mouseData = (BYTE)-delta_x;
			MySendInput(pDevice, &input, sc);
		}
		else if (abs(delta_y) > abs(delta_x)){
			input.mi.dwFlags = MOUSEEVENTF_WHEEL;
			input.mi.mouseData = (BYTE)delta_y;
			MySendInput(pDevice, &input, sc);
		}
	}
	else if (afingers == 3){
		if (sc->hasmoved){
			sc->multitaskingx += delta_x;
			sc->multitaskingy += delta_y;
			if (sc->multitaskinggesturetick > 5 && !sc->multitaskingdone){
				if (abs(sc->multitaskingx) > abs(sc->multitaskingy)){
					BYTE shiftKeys = KBD_LGUI_BIT | KBD_LCONTROL_BIT;
					BYTE keyCodes[KBD_KEY_CODES] = { 0, 0, 0, 0, 0, 0 };
					if (sc->multitaskingx > 0)
						keyCodes[0] = 0x50;
					else
						keyCodes[0] = 0x4F;
					update_keyboard(pDevice, shiftKeys, keyCodes);
					shiftKeys = 0;
					keyCodes[0] = 0x0;
					update_keyboard(pDevice, shiftKeys, keyCodes);
				}
				else if (abs(sc->multitaskingy) > abs(sc->multitaskingx)){
					BYTE shiftKeys = KBD_LGUI_BIT;
					BYTE keyCodes[KBD_KEY_CODES] = { 0, 0, 0, 0, 0, 0 };
					if (sc->multitaskingy < 0)
						keyCodes[0] = 0x2B;
					else
						keyCodes[0] = 0x07;
					update_keyboard(pDevice, shiftKeys, keyCodes);
					shiftKeys = 0;
					keyCodes[0] = 0x0;
					update_keyboard(pDevice, shiftKeys, keyCodes);
				}
				sc->multitaskingdone = true;
				sc->multitaskinggesturetick = -1;
			}
			else if (sc->multitaskingdone){
				if (sc->multitaskinggesturetick > 25){
					sc->multitaskinggesturetick = -1;
					sc->multitaskingx = 0;
					sc->multitaskingy = 0;
					sc->multitaskingdone = false;
				}
			}
#ifdef DEBUG
			CyapaPrint(DEBUG_LEVEL_INFO,DBG_IOCTL,"Multitasking Gestures!\n");
#endif
			sc->multitaskinggesturetick++;
		}
	}

	if (afingers != 3){
		sc->multitaskinggesturetick = 0;
		sc->multitaskingx = 0;
		sc->multitaskingy = 0;
		sc->multitaskingdone = false;
	}


	if (afingers > 0){
		if ((regs->fngr & CYAPA_FNGR_LEFT) != 0 && sc->mousedown == false){
			sc->mousedown = true;

			if (afingers == 1){
				if (sc->y < 400 || sc->x < 400){
					sc->mousebutton = 0;
				}
				else {
					sc->mousebutton = 1;
				}
			}
			else if (afingers == 2){
				sc->mousebutton = 1;
			}
			else if (afingers == 3){
				sc->mousebutton = 2;
			}
			else if (afingers == 4){
				sc->mousebutton = 3;
			}

			input.mi.dx = 0;
			input.mi.dy = 0;
			input.mi.mouseData = 0;
			MySendInput(pDevice, &input, sc);
		}
		if (!overrideDeltas){
			sc->x = x;
			sc->y = y;
		}
	}
	else {
		if (!overrideDeltas){
			sc->x = 0;
			sc->y = 0;
		}
	}

	if ((regs->fngr & CYAPA_FNGR_LEFT) == 0 && sc->mousedown == true && sc->mousedownfromtap != true){
		sc->mousedown = false;

		if (sc->mousebutton == 3){
			BYTE shiftKeys = KBD_LGUI_BIT;
			BYTE keyCodes[KBD_KEY_CODES] = { 0x04, 0, 0, 0, 0, 0 };
			update_keyboard(pDevice, shiftKeys, keyCodes);
			shiftKeys = 0;
			keyCodes[0] = 0x0;
			update_keyboard(pDevice, shiftKeys, keyCodes);

		}
		sc->mousebutton = 0;
		input.mi.dx = 0;
		input.mi.dy = 0;
		input.mi.mouseData = 0;
		MySendInput(pDevice, &input, sc);
	}
}
コード例 #10
0
ファイル: keyboard.c プロジェクト: mjwoodcock/sdl-asylum
int scan_for_key(int c)
{
    if (c >= 0) return read_key();
    update_keyboard();
    return keyboard[-c];
}
コード例 #11
0
int main(int argc, char **argv)
{

    int bytes_written = 0;
    int status = 0;

    printf("Searching for Corsair K70 RGB keyboard...\n");

    dev = find_device(0x1B1C, 0x1B17);

    if(dev == NULL)
    {
        printf("Corsair K70 RGB keyboard not detected :(\n");
        return 1;
    }
    else
    {
        printf("Corsair K70 RGB keyboard detected successfully :)\n");
    }

    handle = usb_open(dev);

    if(handle == NULL)
    {
        printf("USB device handle did not open :(\n");
        return 1;
    }
    else
    {
        printf("USB device handle opened successfully :)\n");
    }

    status = usb_claim_interface(handle, 3);

    status = usb_detach_kernel_driver_np(handle, 3);

    if(status == 0)
    {
        printf("USB interface claimed successfully :)\n");
    }
    else
    {
        printf("USB interface claim failed with error %d :(\n", status);
        return 1;
    }

    // Construct XY lookup table
    unsigned char *keys = position_map;
    float *sizes = size_map;
    for (int y = 0; y < 7; y++)
    {
        unsigned char key;
        int size = 0;

        for (int x = 0; x < 92; x++)
        {
            if (size == 0)
            {
                float sizef = *sizes++;
                if (sizef < 0)
                {
                    size = -sizef * 4;
                    key = 255;
                }
                else
                {
                    key = *keys++;
                    size = sizef * 4;
                }
            }

            led_matrix[y][x] = key;
            size--;
        }

        if (*keys++ != 255 || *sizes++ != 0)
        {
            printf("Bad line %d\n", y);
            return 1;
        }
    }

    while(1)
    {
        for(int i = 0; i < 91; i++)
        {
            for(int x = 0; x < 91; x++)
            {
                for(int y = 0; y < 7; y++)
                {
                    char red = 3.5f * ( sin( ( x / 92.0f ) * 2 * 3.14f ) + 1 );
                    char grn = 3.5f * ( sin( ( ( x / 92.0f ) * 2 * 3.14f ) - ( 6.28f / 3 ) ) + 1 );
                    char blu = 3.5f * ( sin( ( ( x / 92.0f ) * 2 * 3.14f ) + ( 6.28f / 3 ) ) + 1 );

                    set_led( ( x + i ) % 92, y, red, grn, blu );
                }
            }

            update_keyboard();
            usleep(12500);
        }
    }
    return 0;
}