コード例 #1
0
ファイル: input.c プロジェクト: neonmori/sdlpalX
/**
 * Handle keyboard events.
 * @param[in] lpEvent - pointer to the event.
 * @return None
 */
static VOID PAL_KeyboardEventFilter(const SDL_Event *lpEvent)
{
    switch (lpEvent->type) {
        case SDL_KEYDOWN:
            //
            // Pressed a key
            //
            if (lpEvent->key.keysym.mod & KMOD_ALT) {
                if (lpEvent->key.keysym.sym == SDLK_RETURN) {
                    //
                    // Pressed Alt+Enter (toggle fullscreen)...
                    //
                    VIDEO_ToggleFullscreen();
                    return;
                } else if (lpEvent->key.keysym.sym == SDLK_F4) {
                    //
                    // Pressed Alt+F4 (Exit program)...
                    //
                    PAL_Shutdown();
                    exit(0);
                }
            }

            switch (lpEvent->key.keysym.sym) {
#ifdef __SYMBIAN32__
                //
                // Symbian-specific stuff
                //
                case SDLK_0:
                   VIDEO_ToggleScaleScreen();
                   break;
                case SDLK_1:
                   SOUND_AdjustVolume(0);
                   break;
                case SDLK_3:
                   SOUND_AdjustVolume(1);
                   break;
#endif

#ifdef __WINPHONE__
                case SDLK_AC_BACK:
                   if (g_uiLastBackKeyTime != 0 && SDL_GetTicks() - g_uiLastBackKeyTime < 800)
                   {
                      PAL_Shutdown();
                      exit(0);
                   }
                   g_uiLastBackKeyTime = SDL_GetTicks();
                   VIDEO_UpdateScreen(NULL);
                   break;
#endif

                case SDLK_UP:
                case SDLK_KP8:
                    if (gpGlobals->fInBattle || g_InputState.dir != kDirNorth) {
                        g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
                        g_InputState.dir = kDirNorth;
                        g_InputState.dwKeyPress |= kKeyUp;
                    }
                    break;

                case SDLK_DOWN:
                case SDLK_KP2:
                    if (gpGlobals->fInBattle || g_InputState.dir != kDirSouth) {
                        g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
                        g_InputState.dir = kDirSouth;
                        g_InputState.dwKeyPress |= kKeyDown;
                    }
                    break;

                case SDLK_LEFT:
                case SDLK_KP4:
                    if (gpGlobals->fInBattle || g_InputState.dir != kDirWest) {
                        g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
                        g_InputState.dir = kDirWest;
                        g_InputState.dwKeyPress |= kKeyLeft;
                    }
                    break;

                case SDLK_RIGHT:
                case SDLK_KP6:
                    if (gpGlobals->fInBattle || g_InputState.dir != kDirEast) {
                        g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
                        g_InputState.dir = kDirEast;
                        g_InputState.dwKeyPress |= kKeyRight;
                    }
                    break;

#if defined(DINGOO)
                case SDLK_SPACE:
                   g_InputState.dwKeyPress = kKeyMenu;
                   break;

                case SDLK_LCTRL:
                   g_InputState.dwKeyPress = kKeySearch;
                   break;
#else
                case SDLK_ESCAPE:
                case SDLK_INSERT:
                case SDLK_LALT:
                case SDLK_RALT:
                case SDLK_KP0:
                    g_InputState.dwKeyPress |= kKeyMenu;
                    break;

                case SDLK_RETURN:
                case SDLK_SPACE:
                case SDLK_KP_ENTER:
                case SDLK_LCTRL:
                    g_InputState.dwKeyPress |= kKeySearch;
                    break;

                case SDLK_PAGEUP:
                case SDLK_KP9:
                    g_InputState.dwKeyPress |= kKeyPgUp;
                    break;

                case SDLK_PAGEDOWN:
                case SDLK_KP3:
                    g_InputState.dwKeyPress |= kKeyPgDn;
                    break;

                case SDLK_7: //7 for mobile device
                case SDLK_r:
                    g_InputState.dwKeyPress |= kKeyRepeat;
                    break;

                case SDLK_2: //2 for mobile device
                case SDLK_a:
                    g_InputState.dwKeyPress |= kKeyAuto;
                    break;

                case SDLK_d:
                    g_InputState.dwKeyPress |= kKeyDefend;
                    break;

                case SDLK_e:
                    g_InputState.dwKeyPress |= kKeyUseItem;
                    break;

                case SDLK_w:
                    g_InputState.dwKeyPress |= kKeyThrowItem;
                    break;

                case SDLK_q:
                    g_InputState.dwKeyPress |= kKeyFlee;
                    break;

                case SDLK_s:
                    g_InputState.dwKeyPress |= kKeyStatus;
                    break;

                case SDLK_f:
                case SDLK_5: // 5 for mobile device
                    g_InputState.dwKeyPress |= kKeyForce;
                    break;

                case SDLK_HASH: //# for mobile device
                case SDLK_p:
                    VIDEO_SaveScreenshot();
                    break;
#endif

                default:
                    break;
            }
            break;

        case SDL_KEYUP:
            //
            // Released a key
            //
            switch (lpEvent->key.keysym.sym) {
                case SDLK_UP:
                case SDLK_KP8:
                    if (g_InputState.dir == kDirNorth) {
                        g_InputState.dir = g_InputState.prevdir;
                    }
                    g_InputState.prevdir = kDirUnknown;
                    break;

                case SDLK_DOWN:
                case SDLK_KP2:
                    if (g_InputState.dir == kDirSouth) {
                        g_InputState.dir = g_InputState.prevdir;
                    }
                    g_InputState.prevdir = kDirUnknown;
                    break;

                case SDLK_LEFT:
                case SDLK_KP4:
                    if (g_InputState.dir == kDirWest) {
                        g_InputState.dir = g_InputState.prevdir;
                    }
                    g_InputState.prevdir = kDirUnknown;
                    break;

                case SDLK_RIGHT:
                case SDLK_KP6:
                    if (g_InputState.dir == kDirEast) {
                        g_InputState.dir = g_InputState.prevdir;
                    }
                    g_InputState.prevdir = kDirUnknown;
                    break;

                default:
                    break;
            }
            break;
    }
}
コード例 #2
0
ファイル: input.c プロジェクト: niuzb/sdlpal4ios
static VOID
PAL_KeyboardEventFilter(
   const SDL_Event       *lpEvent
)
/*++
  Purpose:

    Handle keyboard events.

  Parameters:

    [IN]  lpEvent - pointer to the event.

  Return value:

    None.

--*/
{
   switch (lpEvent->type)
   {
   case SDL_KEYDOWN:
      //
      // Pressed a key
      //edit by niuzb press f4 then exit
      if (/*lpEvent->key.keysym.mod & KMOD_ALT*/1)
      {
#if 0
		 if (lpEvent->key.keysym.sym == SDLK_RETURN)
         {
            //
            // Pressed Alt+Enter (toggle fullscreen)...
            //
            VIDEO_ToggleFullscreen();
            return;
         }
         else 
#endif
		if (lpEvent->key.keysym.sym == SDLK_F4)
         {
            //
            // Pressed Alt+F4 (Exit program)...
            //
            PAL_Shutdown();
            exit(0);
         }
      }
	  //__android_log_print(ANDROID_LOG_INFO, "libSDL", "key down %c ,%d", lpEvent->key.keysym.sym,lpEvent->key.keysym.sym);
//printf("sdl kp %d is pressed****\n",lpEvent->key.keysym.sym);
      switch (lpEvent->key.keysym.sym)
      {
#ifdef __SYMBIAN32__
      //
      // Symbian-specific stuff
      //
      case SDLK_0:
         VIDEO_ToggleScaleScreen();
         break;
      case SDLK_1:
         SOUND_AdjustVolume(0);
         break;
      case SDLK_3:
         SOUND_AdjustVolume(1);
         break;
#endif

      case SDLK_UP:
      case SDLK_KP8:
         g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
         g_InputState.dir = kDirNorth;
         g_InputState.dwKeyPress |= kKeyUp;
         break;
	  case SDLK_KP2:
	  	g_InputState.dwKeyPress |= kKeySave;
		break;
	  case SDLK_KP4:
	  	g_InputState.dwKeyPress |= kKeyStore;
		break;
          case SDLK_KP5:{
             // printf("sdl kp 5 is pressed\n****");
              g_InputState.dwKeyPress |= kKeyfullblood;
              break;}
      case SDLK_DOWN:
      
         g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
         g_InputState.dir = kDirSouth;
         g_InputState.dwKeyPress |= kKeyDown;
         break;

      case SDLK_LEFT:
      
         g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
         g_InputState.dir = kDirWest;
         g_InputState.dwKeyPress |= kKeyLeft;
         break;

      case SDLK_RIGHT:
      case SDLK_KP6:
         g_InputState.prevdir = (gpGlobals->fInBattle ? kDirUnknown : g_InputState.dir);
         g_InputState.dir = kDirEast;
         g_InputState.dwKeyPress |= kKeyRight;
         break;

      case SDLK_ESCAPE:
      case SDLK_INSERT:
      case SDLK_LALT:
      case SDLK_RALT:
      case SDLK_KP0:
         g_InputState.dwKeyPress |= kKeyMenu;
         break;

      case SDLK_RETURN:
      case SDLK_SPACE:
      case SDLK_KP_ENTER:
         g_InputState.dwKeyPress |= kKeySearch;
         break;

      case SDLK_PAGEUP:
      case SDLK_KP9:
         g_InputState.dwKeyPress |= kKeyPgUp;
         break;

      case SDLK_PAGEDOWN:
      case SDLK_KP3:
         g_InputState.dwKeyPress |= kKeyPgDn;
         break;

      case SDLK_7: //7 for mobile device
      case SDLK_r:
         g_InputState.dwKeyPress |= kKeyRepeat;
         break;

      case SDLK_2: //2 for mobile device
      case SDLK_a:
         g_InputState.dwKeyPress |= kKeyAuto;
         break;

      case SDLK_d:
         g_InputState.dwKeyPress |= kKeyDefend;
         break;

	  
      case SDLK_e:
         g_InputState.dwKeyPress |= kKeyUseItem;
         break;

      case SDLK_w:
         g_InputState.dwKeyPress |= kKeyThrowItem;
         break;

      case SDLK_q:
         g_InputState.dwKeyPress |= kKeyFlee;
         break;

      case SDLK_s:
         g_InputState.dwKeyPress |= kKeyStatus;
         break;

      case SDLK_f:
	  case SDLK_5: // 5 for mobile device
         g_InputState.dwKeyPress |= kKeyForce;
         break;

      case SDLK_HASH: //# for mobile device
      case SDLK_p:
         VIDEO_SaveScreenshot();
         break;

      default:
         break;
      }
      break;

   case SDL_KEYUP:
      //
      // Released a key
      //
      switch (lpEvent->key.keysym.sym)
      {
      case SDLK_UP:
      case SDLK_KP8:
         if (g_InputState.dir == kDirNorth)
         {
            g_InputState.dir = g_InputState.prevdir;
         }
         g_InputState.prevdir = kDirUnknown;
         break;

      case SDLK_DOWN:
      
         if (g_InputState.dir == kDirSouth)
         {
            g_InputState.dir = g_InputState.prevdir;
         }
         g_InputState.prevdir = kDirUnknown;
         break;
case SDLK_KP2:
              g_InputState.dwKeyPress &= ~kKeySave;
              break;
          case SDLK_KP4:
              g_InputState.dwKeyPress &= ~kKeyStore;
              break;
          case SDLK_KP5:
              g_InputState.dwKeyPress &= ~kKeyfullblood;
              break;
      case SDLK_LEFT:
     
         if (g_InputState.dir == kDirWest)
         {
            g_InputState.dir = g_InputState.prevdir;
         }
         g_InputState.prevdir = kDirUnknown;
         break;

      case SDLK_RIGHT:
      case SDLK_KP6:
         if (g_InputState.dir == kDirEast)
         {
            g_InputState.dir = g_InputState.prevdir;
         }
         g_InputState.prevdir = kDirUnknown;
         break;

      default:
         break;
      }
      break;
   }
}
コード例 #3
0
static VOID
PAL_KeyboardEventFilter(
   const SDL_Event       *lpEvent
)
/*++
  Purpose:

    Handle keyboard events.

  Parameters:

    [IN]  lpEvent - pointer to the event.

  Return value:

    None.

--*/
{
   switch (lpEvent->type)
   {
   case SDL_KEYDOWN:
      //
      // Pressed a key
      //
      if (lpEvent->key.keysym.mod & KMOD_ALT)
      {
         if (lpEvent->key.keysym.sym == SDLK_F4)
         {
            //
            // Pressed Alt+F4 (Exit program)...
            //
            PAL_Shutdown();
            exit(0);
         }
      }

      switch (lpEvent->key.keysym.sym)
      {
#ifdef __SYMBIAN32__
      //
      // Symbian-specific stuff
      //
      case SDLK_0:
         VIDEO_ToggleScaleScreen();
         break;
      case SDLK_1:
         SOUND_AdjustVolume(0);
         break;
      case SDLK_3:
         SOUND_AdjustVolume(1);
         break;
#endif

      case SDLK_UP:
	  case SDLK_KP8:
         g_InputState.dir = kDirNorth;
		 g_InputState.dwKeyPress |=kKeyUp;
         g_InputState.dirKeyPress |= kKeyUp;
         break;

      case SDLK_DOWN:
      case SDLK_KP2:
         g_InputState.dir = kDirSouth;
		 g_InputState.dwKeyPress |= kKeyDown;
         g_InputState.dirKeyPress |= kKeyDown;
         break;

      case SDLK_LEFT:
      case SDLK_KP4:
         g_InputState.dir = kDirWest;
		 g_InputState.dwKeyPress |= kKeyLeft;
         g_InputState.dirKeyPress |= kKeyLeft;
         break;

      case SDLK_RIGHT:
      case SDLK_KP6:
         g_InputState.dir = kDirEast;
		 g_InputState.dwKeyPress |= kKeyRight;
         g_InputState.dirKeyPress |= kKeyRight;
         break;

#if defined(DINGOO)
      case SDLK_SPACE:
		 g_InputState.dwKeyPress = kKeyMenu;
         break;

      case SDLK_LCTRL:
		 g_InputState.dwKeyPress = kKeySearch;
         break;
#else
      case SDLK_ESCAPE:
      case SDLK_INSERT:
      case SDLK_LALT:
      case SDLK_RALT:
      case SDLK_KP0:
         g_InputState.dwKeyPress |= kKeyMenu;
         break;

      case SDLK_RETURN:
      case SDLK_SPACE:
      case SDLK_KP_ENTER:
      case SDLK_LCTRL:
         g_InputState.dwKeyPress |= kKeySearch;
         break;

      case SDLK_PAGEUP:
      case SDLK_KP9:
         g_InputState.dwKeyPress |= kKeyPgUp;
         break;

      case SDLK_PAGEDOWN:
      case SDLK_KP3:
         g_InputState.dwKeyPress |= kKeyPgDn;
         break;

      case SDLK_7: //7 for mobile device
      case SDLK_r:
         g_InputState.dwKeyPress |= kKeyRepeat;
         break;

      case SDLK_2: //2 for mobile device
      case SDLK_a:
         g_InputState.dwKeyPress |= kKeyAuto;
         break;

      case SDLK_d:
         g_InputState.dwKeyPress |= kKeyDefend;
         break;

      case SDLK_e:
         g_InputState.dwKeyPress |= kKeyUseItem;
         break;

      case SDLK_w:
         g_InputState.dwKeyPress |= kKeyThrowItem;
         break;

      case SDLK_q:
         g_InputState.dwKeyPress |= kKeyFlee;
         break;

      case SDLK_s:
         g_InputState.dwKeyPress |= kKeyStatus;
         break;

      case SDLK_f:
      case SDLK_5: // 5 for mobile device
         g_InputState.dwKeyPress |= kKeyForce;
         break;

      case SDLK_HASH: //# for mobile device
      case SDLK_p:
         VIDEO_SaveScreenshot();
         break;
#endif

      default:
         break;
      }
      break;

   case SDL_KEYUP:
      //
      // Released a key
      //
      switch (lpEvent->key.keysym.sym)
      {
      case SDLK_UP:
      case SDLK_KP8:
		  if ((g_InputState.dirKeyPress & kKeyUp) != 0) {
			  g_InputState.dirKeyPress ^= kKeyUp;
		  }
		  
         g_InputState.dir = get_dir_by_key(g_InputState.dirKeyPress);
         break;

      case SDLK_DOWN:
      case SDLK_KP2:
		  if ((g_InputState.dirKeyPress & kKeyDown) != 0) {
			  g_InputState.dirKeyPress ^= kKeyDown;
		  }
         g_InputState.dir = get_dir_by_key(g_InputState.dirKeyPress);
         break;

      case SDLK_LEFT:
      case SDLK_KP4:
		  if ((g_InputState.dirKeyPress & kKeyLeft) != 0) {
			  g_InputState.dirKeyPress ^= kKeyLeft;
		  }
         g_InputState.dir = get_dir_by_key(g_InputState.dirKeyPress);
         break;

      case SDLK_RIGHT:
      case SDLK_KP6:
		  if ((g_InputState.dirKeyPress & kKeyRight) != 0) {
			  g_InputState.dirKeyPress ^= kKeyRight;
		  }
         g_InputState.dir = get_dir_by_key(g_InputState.dirKeyPress);
         break;

      default:
         break;
      }
      break;
   }
}