Exemple #1
0
//Keyboard keyDown returns whether or not the key is physically down, while input keyDown does something similar to how a key is registered in text input.
bool AKeyboard::keyDown(int _key)
{
	if (keystate[_key])
	{
		return true;
	}
	else if (keystate[SDL_GetScancodeFromKey(_key)])
	{
		return true;
	}
	return false;
}
Exemple #2
0
bool Keyboard::isPressed(Key k)
{
	const Uint8* pressedKeys = SDL_GetKeyboardState(NULL);
	
	int scanCode = SDL_GetScancodeFromKey(k);
	
	if (scanCode < m_numKeys)
		return (bool) pressedKeys[scanCode];
		
	else
		return false;
}
Exemple #3
0
Gosu::Button Gosu::Input::charToId(wchar_t ch)
{
    std::wstring string(1, ch);
    SDL_Keycode keycode = SDL_GetKeyFromName(wstringToUTF8(string).c_str());
    
    if (keycode == SDLK_UNKNOWN) {
        return noButton;
    }
    else {
        return Button(SDL_GetScancodeFromKey(keycode));
    }
}
Exemple #4
0
bool Keyboard::isDown(const std::vector<Key> &keylist) const
{
	const Uint8 *state = SDL_GetKeyboardState(nullptr);

	for (Key key : keylist)
	{
		SDL_Scancode scancode = SDL_GetScancodeFromKey(keymap[key]);
		if (state[scancode])
			return true;
	}

	return false;
}
Exemple #5
0
static VOID
PAL_UpdateKeyboardState(
   VOID
)
/*++
  Purpose:

    Poll & update keyboard state.

  Parameters:

    None.

  Return value:

    None.

--*/
{
   static DWORD   rgdwKeyLastTime[sizeof(g_KeyMap) / sizeof(g_KeyMap[0])] = {0};
   LPCBYTE        keyState = (LPCBYTE)SDL_GetKeyboardState(NULL);
   int            i;
   DWORD          dwCurrentTime = SDL_GetTicks();

   for (i = 0; i < sizeof(g_KeyMap) / sizeof(g_KeyMap[0]); i++)
   {
      if (keyState[SDL_GetScancodeFromKey(g_KeyMap[i][0])])
      {
         if (dwCurrentTime > rgdwKeyLastTime[i])
         {
            PAL_KeyDown(g_KeyMap[i][1], (rgdwKeyLastTime[i] != 0));
            if (gConfig.fEnableKeyRepeat)
            {
               rgdwKeyLastTime[i] = dwCurrentTime + (rgdwKeyLastTime[i] == 0 ? 200 : 75);
            }
            else
            {
               rgdwKeyLastTime[i] = 0xFFFFFFFF;
            }
         }
      }
      else
      {
         if (rgdwKeyLastTime[i] != 0)
         {
            PAL_KeyUp(g_KeyMap[i][1]);
            rgdwKeyLastTime[i] = 0;
         }
      }
   }
}
Exemple #6
0
// eu.keyboard.key_down(key:key_string) -> boolean
static int eu_keyboard_key_down(lua_State *L)
{
	const char *keystr = luaL_checkstring(L, 1);

	lua_pushstring(L, EU_STR_TO_SDLK_TBL); // key, tblnm
	lua_gettable(L, LUA_REGISTRYINDEX); // key, tbl
	lua_pushstring(L, keystr); // key, tbl, key
	lua_gettable(L, -2); // key, tbl, sdlk
	// get the sdlk constant
	int sdlk = lua_tointeger(L, -1);
	int sc = SDL_GetScancodeFromKey(sdlk);
	lua_pushboolean(L, KEYBOARD_STATE[sc]);
	return 1;
}
Exemple #7
0
Keyboard::Scancode Keyboard::getScancodeFromKey(Key key) const
{
	Scancode scancode = SCANCODE_UNKNOWN;

	if (key != KEY_MAX_ENUM)
	{
		SDL_Keycode sdlkey = keymap[key];

		SDL_Scancode sdlscancode = SDL_GetScancodeFromKey(sdlkey);
		scancodes.find(sdlscancode, scancode);
	}

	return scancode;
}
void Game::HandleKeys(){
  SDL_PumpEvents();
  const Uint8 *state = SDL_GetKeyboardState(NULL);

  //Q
  if (state[SDL_GetScancodeFromKey(SDLK_q)]) {
    exit(0);
  }

  //UP
  if (state[SDL_SCANCODE_UP]){
    _iSpeedY--;
    _iSpeedY = std::max(-_iMAXSPEED, _iSpeedY);

#ifdef DEBUG
    std::cout << "up key down. Y Speed is " << _iSpeedY << std::endl;
#endif    
  }

  //RIGHT
  if (state[SDL_SCANCODE_RIGHT]){
    _iSpeedX++;
    _iSpeedX = std::min(_iMAXSPEED, _iSpeedX);

#ifdef DEBUG
    std::cout << "right key down. X Speed is " << _iSpeedX << std::endl;
#endif    
  }

  //DOWN
  if (state[SDL_SCANCODE_DOWN]){
    _iSpeedY++;
    _iSpeedY = std::min(_iMAXSPEED, _iSpeedY);

#ifdef DEBUG
    std::cout << "down key down. Y Speed is " << _iSpeedY << std::endl;
#endif    
  }

  //LEFT
  if (state[SDL_SCANCODE_LEFT]){
    _iSpeedX--;
    _iSpeedX = std::max(-_iMAXSPEED, _iSpeedX);

#ifdef DEBUG
    std::cout << "left key down. X Speed is " << _iSpeedX << std::endl;
#endif    
  }
}
Exemple #9
0
/* TODO: maybe it's not necessary to SDL_PumpEvents every time, since
   it's usually done before this function is called */
int GetKeyboard(int key)
{
  // returns 0 if the key has been depressed, else returns 1 and sets key to code recd.
  int keystate_size;
  Uint8* keystate;
  //SDL_PumpEvents();
#if SDL_VERSION_ATLEAST(1, 3, 0)
  keystate = SDL_GetKeyboardState(&keystate_size);
  SDLKey scancode = SDL_GetScancodeFromKey(key);
  return keystate[scancode];
#else
  keystate = SDL_GetKeyState(&keystate_size);
  return keystate[key];
#endif
}
Exemple #10
0
void Events_Manager::RefreshKeys()
    {
    //przypisywanie aktualnej tablicy stanów do poprzedniej
    previous_keys_state = keys_pressed;
    SDL_PollEvent(&singleton->event);
    const Uint8 *state = SDL_GetKeyboardState(NULL);
    SDL_GetMouseState(&singleton->mouse_x, &singleton->mouse_y);

    //uaktualnianie tablicy stanów
    for(std::map<SDL_Keycode,bool>::iterator it = keys_pressed.begin(); it != keys_pressed.end(); ++it)
    {
        keys_pressed[it->first] = state[SDL_GetScancodeFromKey(it->first)];
        keys_clicked[it->first] = (!keys_pressed[it->first] && previous_keys_state[it->first]);
    }
}
Exemple #11
0
static bool sdl_key_pressed(int key)
{
   int num_keys;
   unsigned sym          = rarch_keysym_lut[(enum retro_key)key];
#ifdef HAVE_SDL2
   const uint8_t *keymap = SDL_GetKeyboardState(&num_keys);
   sym                   = SDL_GetScancodeFromKey(sym);
#else
   const uint8_t *keymap = SDL_GetKeyState(&num_keys);
#endif

   if (sym >= (unsigned)num_keys)
      return false;

   return keymap[sym];
}
Exemple #12
0
bool sdlwrap_key_pressed(int key)
{
   int num_keys;
#if SDL_MODERN
   Uint8 *keymap = SDL_GetKeyboardState(&num_keys);
   key = SDL_GetScancodeFromKey(key);
   if (key >= num_keys)
      return false;

   return keymap[key];
#else
   Uint8 *keymap = SDL_GetKeyState(&num_keys);
   if (key >= num_keys)
      return false;

   return keymap[key];
#endif
}
	int LuaEnv_Input::IsKeyPressed(lua_State *state)
	{
		// First argument is keyboard key
		std::string keyboardKeyName = luaL_checkstring(state, 1);

		lua_settop(state, 0);

		SDL_Keycode keyCode = SDL_GetKeyFromName(keyboardKeyName.c_str());

		if(keyCode == SDLK_UNKNOWN)
			lua_pushboolean(state, 0);
		else
		{
			const Uint8 *keyboardState = SDL_GetKeyboardState(NULL);
			lua_pushboolean(state, keyboardState[SDL_GetScancodeFromKey(keyCode)]);
		}

		return 1;
	}
Exemple #14
0
static bool sdl_key_pressed(int key)
{
   int num_keys;
   const uint8_t *keymap;
   unsigned sym;

   if (key >= RETROK_LAST)
      return false;

   sym = input_keymaps_translate_rk_to_keysym((enum retro_key)key);

#ifdef HAVE_SDL2
   sym = SDL_GetScancodeFromKey(sym);
   keymap = SDL_GetKeyboardState(&num_keys);
#else
   keymap = SDL_GetKeyState(&num_keys);
#endif
   if (sym >= (unsigned)num_keys)
      return false;

   return keymap[sym];
}
Exemple #15
0
// make fast conversion tables from the general table
static void MakeConversionTables(void)
{
  // clear conversion tables
  for (int i = 0; i < ARRAYCOUNT(_aiScancodeToKid); i++) {
    _aiScancodeToKid[i] = -1;
  }

  // for each Key
  for (INDEX iKey=0; iKey<ARRAYCOUNT(_akcKeys); iKey++) {
    const KeyConversion &kc = _akcKeys[iKey];

    // get codes
    const INDEX iKID  = kc.kc_iKID;
    //INDEX iScan = kc.kc_iScanCode;
    const SDL_Keycode iVirt = kc.kc_iVirtKey;

    if (iVirt>=0) {
      _aiScancodeToKid[SDL_GetScancodeFromKey(iVirt)] = iKID;
    }
  }

  _aiScancodeToKid[SDL_SCANCODE_UNKNOWN] = -1;  // in case several items set this.
}
Exemple #16
0
void Game::HandleEvents(){

	SDL_Event event;
	while (SDL_PollEvent(&event))
	{

		if (event.type == SDL_QUIT)
			ShutDown();

		//Uint8* keystates = SDL_GetKeyState(NULL);
		int numkeys = 0;
		Uint8* keystates = (Uint8*)SDL_GetKeyboardState(&numkeys);

		//if(keystates[SDLK_q])
		//    ShutDown();

		if (keystates[SDL_GetScancodeFromKey(SDLK_q)])
			ShutDown();

		game_state->HandleEvents(keystates, event, control_type);
	}

}
Exemple #17
0
bool InputSystem::isKeyDown(const SDL_Keycode key) const
{
	return SDL_GetKeyboardState(nullptr)[SDL_GetScancodeFromKey(key)];
}
void PSP_PumpEvents(_THIS)
{
    int i;
    enum PspHprmKeys keys;
    enum PspHprmKeys changed;
    static enum PspHprmKeys old_keys = 0;
    SDL_Keysym sym;

    SDL_SemWait(event_sem);
    keys = hprm;
    SDL_SemPost(event_sem);

    /* HPRM Keyboard */
    changed = old_keys ^ keys;
    old_keys = keys;
    if(changed) {
        for(i=0; i<sizeof(keymap_psp)/sizeof(keymap_psp[0]); i++) {
            if(changed & keymap_psp[i].id) {
                sym.scancode = keymap_psp[i].id;
                sym.sym = keymap_psp[i].sym;

                /* out of date
                SDL_PrivateKeyboard((keys & keymap_psp[i].id) ?
                            SDL_PRESSED : SDL_RELEASED,
                            &sym);
        */
                SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
                                    SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap_psp[i].sym));
            }
        }
    }

#ifdef PSPIRKEYB
    if (irkbd_ready) {
            unsigned char buffer[255];
        int i, length, count;
        SIrKeybScanCodeData *scanData;

            if(pspIrKeybReadinput(buffer, &length) >= 0) {
                if((length % sizeof(SIrKeybScanCodeData)) == 0){
                    count = length / sizeof(SIrKeybScanCodeData);
                    for( i=0; i < count; i++ ) {
                unsigned char raw, pressed;
                        scanData=(SIrKeybScanCodeData*) buffer+i;
                        raw = scanData->raw;
                        pressed = scanData->pressed;
                sym.scancode = raw;
                sym.sym = keymap[raw];
                /* not tested */
                /* SDL_PrivateKeyboard(pressed?SDL_PRESSED:SDL_RELEASED, &sym); */
                SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
                                    SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap[raw]));

                }
            }
        }
    }
#endif
    sceKernelDelayThread(0);

    return;
}
std::string ConfigManager::getNameForKey (int key) const
{
	const SDL_Scancode scanCode = SDL_GetScancodeFromKey(key);
	return SDL_GetScancodeName(scanCode);
}
Exemple #20
0
/*
* BEE::get_key_state() - Return whether the given keycode is pressed
* ! When the function is called with a SDL_Keycode, simply convert it into an SDL_Scancode and call the function again
* @k: the keycode to check
*/
bool BEE::get_key_state(SDL_Keycode k) const {
	return get_key_state(SDL_GetScancodeFromKey(k));
}
Exemple #21
0
void Input::RegisterKeyEvent(SDL_Keycode key, std::function<void()> action)
{
	auto pair = std::pair<SDL_Scancode, std::function<void()>>(SDL_GetScancodeFromKey(key), action);
	function_map.insert(function_map.begin(), pair);
}
Exemple #22
0
bool CInput::KeyState(int Key) const
{
	return m_aInputState[Key>=KEY_MOUSE_1 ? Key : SDL_GetScancodeFromKey(KeyToKeycode(Key))];
}
Exemple #23
0
	bool Display::isKeyDown(SDL_Keycode key)
	{
		unsigned int keycode = SDL_GetScancodeFromKey(key);
		if (m_keystate[keycode]) return true;
		return false;
	}
Exemple #24
0
int main(int argc, char *argv[])
{
	SDL_Init(SDL_INIT_EVERYTHING);

	SDL_Window *window;
	window = SDL_CreateWindow("SDLwindow", 600, 300, MainWindowWidth, MainWindowHigh, SDL_WINDOW_SHOWN);

	SDL_Renderer* renderer = NULL;
	renderer =  SDL_CreateRenderer( window, 0, SDL_RENDER_TARGETS_RESET);

	SDL_SetRenderDrawColor(renderer,255,255,255,255);
	SDL_RenderClear( renderer );

	SDL_SetRenderDrawColor(renderer,0,0,0,0);
	SDL_RenderDrawLine(renderer,MainWindowWidth/12,MainWindowHigh-30,MainWindowWidth/12,MainWindowHigh-70);
	SDL_RenderDrawLine(renderer,MainWindowWidth/12,MainWindowHigh-30,MainWindowWidth/12-10,MainWindowHigh-50);
	SDL_RenderDrawLine(renderer,MainWindowWidth/12,MainWindowHigh-30,MainWindowWidth/12+10,MainWindowHigh-50);

	SDL_RenderDrawLine(renderer,MainWindowWidth/12*11,MainWindowHigh-30,MainWindowWidth/12*11,MainWindowHigh-70);
	SDL_RenderDrawLine(renderer,MainWindowWidth/12*11,MainWindowHigh-70,MainWindowWidth/12*11-10,MainWindowHigh-50);
	SDL_RenderDrawLine(renderer,MainWindowWidth/12*11,MainWindowHigh-70,MainWindowWidth/12*11+10,MainWindowHigh-50);

	Road road;
	road.Draw(renderer);

	Car object;
	object.SetX(MainWindowWidth/5*3);
	object.SetY(MainWindowHigh/5*3);
	object.SetAngle(0);
	object.Draw(renderer);

	Actions actions;

	SDL_Event event;
	int rl=0,rp=0;

	while (1) 
	{
		while (SDL_PollEvent(&event)) 
		{
			switch (event.type) 
			{
			case SDL_KEYDOWN:
				{
					if (SDL_GetScancodeFromKey(event.key.keysym.sym)==SDL_SCANCODE_LEFT)
					{
						if (((object.GetX()>=MainWindowWidth/2-10)&&(object.GetDirection()==true))||
							((object.GetX()<=MainWindowWidth/2+10)&&(object.GetDirection()==false)))
						{
							bool AChecked=false;
							if ((object.GetX()<MainWindowWidth/2+10)&&(object.GetX()>MainWindowWidth/2-10))
							{
								actions.ScanA(object,road);
								AChecked=true;
							}
							if (rp==1)
							{
								rl=0;
								rp=0;
							}
							if (rl==0)
							{
								object.RotateLeft();
								rl++;
							}
							object.Rotate90(renderer);
							road.Draw(renderer);
							if (!AChecked)
								actions.ScanA(object,road);

							actions.ScanBC(object,road);
							actions.ActionOutput();
						}
					}
					if (SDL_GetScancodeFromKey(event.key.keysym.sym)==SDL_SCANCODE_RIGHT)
					{
						if (((object.GetX()>=MainWindowWidth/2-10)&&(object.GetDirection()==false))||
							((object.GetX()<=MainWindowWidth/2+10)&&(object.GetDirection()==true)))
						{
							bool AChecked=false;
							if ((object.GetX()<MainWindowWidth/2+10)&&(object.GetX()>MainWindowWidth/2-10))
							{
								actions.ScanA(object,road);
								AChecked=true;
							}
							actions.ScanA(object,road);
							if (rl==1)
							{
								rl=0;
								rp=0;
							}
							if (rp==0)
							{
								object.RotateRight();
								rp++;
							}
							object.Rotate90(renderer);
							road.Draw(renderer);
							if (!AChecked)
								actions.ScanA(object,road);
							actions.ScanBC(object,road);
							actions.ActionOutput();
						}
					}
					if (SDL_GetScancodeFromKey(event.key.keysym.sym)==SDL_SCANCODE_UP)
					{
						if ((object.GetX()<MainWindowWidth/2-10)||(object.GetX()>MainWindowWidth/2+10))
						{
							road.Draw(renderer);
							road.Move(object.GetDirection());
							Sleep(50);
						}
					}
					if (SDL_GetScancodeFromKey(event.key.keysym.sym)==SDL_SCANCODE_ESCAPE)
						return 0;
				}
				break;
			case SDL_QUIT:
				exit(0);
			}
		}
	}

	SDL_DestroyWindow(window); 
	SDL_Quit();

	return 0;
}
bool DeveloperConsole::filterKeys(Uint8* keyStates) {
    keyStates[SDL_GetScancodeFromKey(SDLK_BACKQUOTE)] = false;
    
    return false;
}
Exemple #26
0
int Keyboard_GetKeyTrg(int cual)
{
  return(g_Keyboard.trg[SDL_GetScancodeFromKey(cual)]) ;
}
Exemple #27
0
bool ImGui_ImplSdl2_Init(SDL::Window &window)
{
	ImGuiIO& io = ImGui::GetIO();

	// Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
	io.KeyMap[ImGuiKey_Tab] = SDL_GetScancodeFromKey(SDLK_TAB);
	io.KeyMap[ImGuiKey_LeftArrow] = SDL_GetScancodeFromKey(SDLK_LEFT);
	io.KeyMap[ImGuiKey_RightArrow] = SDL_GetScancodeFromKey(SDLK_RIGHT);
	io.KeyMap[ImGuiKey_UpArrow] = SDL_GetScancodeFromKey(SDLK_UP);
	io.KeyMap[ImGuiKey_DownArrow] = SDL_GetScancodeFromKey(SDLK_DOWN);
	io.KeyMap[ImGuiKey_Home] = SDL_GetScancodeFromKey(SDLK_HOME);
	io.KeyMap[ImGuiKey_End] = SDL_GetScancodeFromKey(SDLK_END);
	io.KeyMap[ImGuiKey_Delete] = SDL_GetScancodeFromKey(SDLK_DELETE);
	io.KeyMap[ImGuiKey_Backspace] = SDL_GetScancodeFromKey(SDLK_BACKSPACE);
	io.KeyMap[ImGuiKey_Enter] = SDL_GetScancodeFromKey(SDLK_RETURN);
	io.KeyMap[ImGuiKey_Escape] = SDL_GetScancodeFromKey(SDLK_ESCAPE);
	io.KeyMap[ImGuiKey_A] = SDLK_a;
	io.KeyMap[ImGuiKey_C] = SDLK_c;
	io.KeyMap[ImGuiKey_V] = SDLK_v;
	io.KeyMap[ImGuiKey_X] = SDLK_x;
	io.KeyMap[ImGuiKey_Y] = SDLK_y;
	io.KeyMap[ImGuiKey_Z] = SDLK_z;

	io.RenderDrawListsFn = ImGui_ImplSdl2_RenderDrawLists;
	io.SetClipboardTextFn = ImGui_ImplSdl2_SetClipboardText;
	io.GetClipboardTextFn = ImGui_ImplSdl2_GetClipboardText;

#ifdef _MSC_VER
	SDL_SysWMinfo info;
	if (window.GetWMInfo(&info) && info.subsystem == SDL_SYSWM_WINDOWS)
		io.ImeWindowHandle = info.info.win.window;
#endif

	return true;
}
Exemple #28
0
void Keyboard_ProcessKeyDown(int tecla)
{
  g_Keyboard.trg[SDL_GetScancodeFromKey(tecla)] = true;
  g_Keyboard.cnt[SDL_GetScancodeFromKey(tecla)] = true;
}
Exemple #29
0
void Keyboard_ProcessKeyUp(int tecla)
{
  g_Keyboard.cnt[SDL_GetScancodeFromKey(tecla)] = false;
}
Exemple #30
0
int Keyboard_GetKeyCnt(int cual)
{
  return(g_Keyboard.cnt[SDL_GetScancodeFromKey(cual)]) ;
}