Beispiel #1
0
WPJInputUtil::~WPJInputUtil()
{
	ClearAllTriggedEvents();

	if (al_is_keyboard_installed())
		al_unregister_event_source(m_pEventQueue, al_get_keyboard_event_source());

	if (al_is_mouse_installed())
		al_unregister_event_source(m_pEventQueue, al_get_mouse_event_source());

	al_destroy_event_queue(m_pEventQueue);
}
Beispiel #2
0
static void *wakeup_thread(ALLEGRO_THREAD *thread, void *user)
{
   al_rest(1);
   while (!al_get_thread_should_stop(thread)) {
      /* If the program uses timers, this hack is not required usually. */
      if (_al_get_active_timers_count())
         break;
      if (!al_is_keyboard_installed())
         break;
      wakeup_with_fake_timer_event();
      al_rest(0.01);
   }
   return user;
}
Beispiel #3
0
/*
 * This reads one keystroke from the keyboard, and the current state of
 * the modifier keys (ALT, SHIFT, etc).  Returns -1 on error, 0 if no data
 * is ready, 1 on a keypress, and 2 on keyrelease.
 * This is a non-blocking call.
 */
static int
allegro_Read(MWKEY *kbuf, MWKEYMOD *modifiers, MWSCANCODE *scancode)
{

  int newkey;
  static int mwkey,scanvalue;

  if (closedown == 1) return -2; /* special case ESC - terminate application*/

  if (!al_is_keyboard_installed()) return 0;

  if (al_get_next_event(a_event_queue_k, &a_event)){
     /* there are further key events */
	 if (a_event.type == ALLEGRO_EVENT_KEY_CHAR) {
	  newkey = a_event.keyboard.unichar;  
	  al_get_keyboard_state(&kbdstate);
	  char ASCII = newkey & 0xff;  
	  mwkey = ASCII;
	  //fprintf(stderr,"key char:%d,%c\n",ASCII,ASCII);  fflush(stderr);
	  scanvalue = a_event.keyboard.keycode; 
     } else {
         if (a_event.type == ALLEGRO_EVENT_KEY_UP) {
            *kbuf = mwkey;		
            *scancode = scanvalue;
            return 2; //key released    
	    } else {
	        //fprintf(stderr,"NO key\n");  fflush(stderr);
	        return 0;
        }
	}

   *modifiers = 0;
   if (al_key_down(&kbdstate, ALLEGRO_KEY_ESCAPE)) return -2; /* special case ESC - terminate application*/

   if (al_key_down(&kbdstate, ALLEGRO_KEYMOD_SHIFT)) *modifiers |= MWKMOD_SHIFT;
   if (al_key_down(&kbdstate, ALLEGRO_KEYMOD_CTRL))  *modifiers |= MWKMOD_CTRL;
   if (al_key_down(&kbdstate, ALLEGRO_KEYMOD_ALT))   *modifiers |= MWKMOD_ALT;
   if (al_key_down(&kbdstate, ALLEGRO_KEYMOD_ALTGR)) *modifiers |= MWKMOD_ALTGR;
   if (al_key_down(&kbdstate, ALLEGRO_KEYMOD_LWIN))  *modifiers |= MWKMOD_LMETA; *modifiers |= MWKMOD_META;
   if (al_key_down(&kbdstate, ALLEGRO_KEYMOD_RWIN))  *modifiers |= MWKMOD_RMETA; *modifiers |= MWKMOD_META;
   save_modifiers=*modifiers;
   
    *kbuf = mwkey;		
    *scancode = scanvalue;

    return 1;		/* keypress received*/
  } 
return 0; //if no event received

}
Beispiel #4
0
bool System::shutdownSharedSystem()
{
  if (al_is_joystick_installed())
    al_uninstall_joystick();
  if (al_is_mouse_installed())
    al_uninstall_mouse();
  if (al_is_keyboard_installed())
    al_uninstall_keyboard();
  al_shutdown_image_addon();
  if (al_is_system_installed())
    al_uninstall_system();

  return true;
}
Beispiel #5
0
static int
allegro_Poll(void)
{
//  fprintf(stderr,"polling keys\n");  fflush(stderr);

  if (!al_is_keyboard_installed()) return 0;

  if (al_peek_next_event(a_event_queue_k, &a_event)) return 1; //read event in read function
  
  if (al_get_next_event(a_event_queue_d, &a_event)) //remove any event from display queue
    if (a_event.type == ALLEGRO_EVENT_DISPLAY_CLOSE){
         closedown=1;
         return 1; //i.e. received the "closedown" key
    }
  
  return 0;
}
Beispiel #6
0
bool WPJInputUtil::Init()
{
	int bRet;

	//	init input hardware driver
	bRet = al_is_keyboard_installed() && al_is_mouse_installed();

	//	init event_queue
	m_pEventQueue = al_create_event_queue();
	if (bRet && m_pEventQueue)
	{
		al_register_event_source(m_pEventQueue, al_get_keyboard_event_source());
		al_register_event_source(m_pEventQueue, al_get_mouse_event_source());
		al_register_event_source(m_pEventQueue, al_get_display_event_source(m_pDisplay));
	}

	return bRet;
}
Beispiel #7
0
static int allua_keyboard_is_installed(lua_State * L)
{
   lua_pushboolean(L, al_is_keyboard_installed());
   return 1;
}