Ignore:
Timestamp:
Apr 8, 2013, 3:54:07 AM (9 years ago)
Author:
sam
Message:

input: make keyboard state platform-independent.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/platform/sdl/sdlinput.cpp

    r2644 r2645  
    144144    Input::SetMousePos(mouse);
    145145
     146    /* Pump all joystick events because no event is coming to us. */
    146147#   if SDL_FORCE_POLL_JOYSTICK && EMSCRIPTEN
    147     /* Pump all joystick events because no event is coming to us. */
    148148    SDL_JoystickUpdate();
    149149    for (int j = 0; j < m_joysticks.Count(); j++)
     
    198198
    199199    /* Send the whole keyboard state to the input system */
    200 #if 0
    201     Uint8 *keystate = SDL_GetKeyState(nullptr);
    202     for (int i = 0; i < 256; i++)
    203         if (keystate[i])
    204             Input::KeyPressed(i, seconds);
    205 #else
     200    Array<uint8_t> &lolstate = Input::GetKeyboardState();
     201
     202#   if SDL_VERSION_ATLEAST(1,3,0)
     203    Uint8 *sdlstate = SDL_GetKeyboardState(nullptr);
     204#   else
     205    Uint8 *sdlstate = SDL_GetKeyState(nullptr);
     206#   endif
     207
     208    lolstate[Key::Unknown] = sdlstate[SDLK_UNKNOWN];
     209    lolstate[Key::Backspace] = sdlstate[SDLK_BACKSPACE];
     210    lolstate[Key::Tab] = sdlstate[SDLK_TAB];
     211    lolstate[Key::Clear] = sdlstate[SDLK_CLEAR];
     212    lolstate[Key::Return] = sdlstate[SDLK_RETURN];
     213    lolstate[Key::Pause] = sdlstate[SDLK_PAUSE];
     214    lolstate[Key::Escape] = sdlstate[SDLK_ESCAPE];
     215    lolstate[Key::Space] = sdlstate[SDLK_SPACE];
     216    lolstate[Key::Exclaim] = sdlstate[SDLK_EXCLAIM];
     217    lolstate[Key::DoubleQuote] = sdlstate[SDLK_QUOTEDBL];
     218    lolstate[Key::Hash] = sdlstate[SDLK_HASH];
     219    lolstate[Key::Dollar] = sdlstate[SDLK_DOLLAR];
     220    lolstate[Key::Ampersand] = sdlstate[SDLK_AMPERSAND];
     221    lolstate[Key::Quote] = sdlstate[SDLK_QUOTE];
     222    lolstate[Key::LeftParen] = sdlstate[SDLK_LEFTPAREN];
     223    lolstate[Key::RightParen] = sdlstate[SDLK_RIGHTPAREN];
     224    lolstate[Key::Asterisk] = sdlstate[SDLK_ASTERISK];
     225    lolstate[Key::Plus] = sdlstate[SDLK_PLUS];
     226    lolstate[Key::Comma] = sdlstate[SDLK_COMMA];
     227    lolstate[Key::Minus] = sdlstate[SDLK_MINUS];
     228    lolstate[Key::Period] = sdlstate[SDLK_PERIOD];
     229    lolstate[Key::Slash] = sdlstate[SDLK_SLASH];
     230    lolstate[Key::K0] = sdlstate[SDLK_0];
     231    lolstate[Key::K1] = sdlstate[SDLK_1];
     232    lolstate[Key::K2] = sdlstate[SDLK_2];
     233    lolstate[Key::K3] = sdlstate[SDLK_3];
     234    lolstate[Key::K4] = sdlstate[SDLK_4];
     235    lolstate[Key::K5] = sdlstate[SDLK_5];
     236    lolstate[Key::K6] = sdlstate[SDLK_6];
     237    lolstate[Key::K7] = sdlstate[SDLK_7];
     238    lolstate[Key::K8] = sdlstate[SDLK_8];
     239    lolstate[Key::K9] = sdlstate[SDLK_9];
     240    lolstate[Key::Colon] = sdlstate[SDLK_COLON];
     241    lolstate[Key::Semicolon] = sdlstate[SDLK_SEMICOLON];
     242    lolstate[Key::Less] = sdlstate[SDLK_LESS];
     243    lolstate[Key::Equals] = sdlstate[SDLK_EQUALS];
     244    lolstate[Key::Greater] = sdlstate[SDLK_GREATER];
     245    lolstate[Key::Question] = sdlstate[SDLK_QUESTION];
     246    lolstate[Key::At] = sdlstate[SDLK_AT];
     247
     248    lolstate[Key::LeftBracket] = sdlstate[SDLK_LEFTBRACKET];
     249    lolstate[Key::BackSlash] = sdlstate[SDLK_BACKSLASH];
     250    lolstate[Key::RightBracket] = sdlstate[SDLK_RIGHTBRACKET];
     251    lolstate[Key::Caret] = sdlstate[SDLK_CARET];
     252    lolstate[Key::Underscore] = sdlstate[SDLK_UNDERSCORE];
     253    lolstate[Key::Backquote] = sdlstate[SDLK_BACKQUOTE];
     254    lolstate[Key::A] = sdlstate[SDLK_a];
     255    lolstate[Key::B] = sdlstate[SDLK_b];
     256    lolstate[Key::C] = sdlstate[SDLK_c];
     257    lolstate[Key::D] = sdlstate[SDLK_d];
     258    lolstate[Key::E] = sdlstate[SDLK_e];
     259    lolstate[Key::F] = sdlstate[SDLK_f];
     260    lolstate[Key::G] = sdlstate[SDLK_g];
     261    lolstate[Key::H] = sdlstate[SDLK_h];
     262    lolstate[Key::I] = sdlstate[SDLK_i];
     263    lolstate[Key::J] = sdlstate[SDLK_j];
     264    lolstate[Key::K] = sdlstate[SDLK_k];
     265    lolstate[Key::L] = sdlstate[SDLK_l];
     266    lolstate[Key::M] = sdlstate[SDLK_m];
     267    lolstate[Key::N] = sdlstate[SDLK_n];
     268    lolstate[Key::O] = sdlstate[SDLK_o];
     269    lolstate[Key::P] = sdlstate[SDLK_p];
     270    lolstate[Key::Q] = sdlstate[SDLK_q];
     271    lolstate[Key::R] = sdlstate[SDLK_r];
     272    lolstate[Key::S] = sdlstate[SDLK_s];
     273    lolstate[Key::T] = sdlstate[SDLK_t];
     274    lolstate[Key::U] = sdlstate[SDLK_u];
     275    lolstate[Key::V] = sdlstate[SDLK_v];
     276    lolstate[Key::W] = sdlstate[SDLK_w];
     277    lolstate[Key::X] = sdlstate[SDLK_x];
     278    lolstate[Key::Y] = sdlstate[SDLK_y];
     279    lolstate[Key::Z] = sdlstate[SDLK_z];
     280    lolstate[Key::Delete] = sdlstate[SDLK_DELETE];
     281
     282    lolstate[Key::World0] = sdlstate[SDLK_WORLD_0];
     283    lolstate[Key::World1] = sdlstate[SDLK_WORLD_1];
     284    lolstate[Key::World2] = sdlstate[SDLK_WORLD_2];
     285    lolstate[Key::World3] = sdlstate[SDLK_WORLD_3];
     286    lolstate[Key::World4] = sdlstate[SDLK_WORLD_4];
     287    lolstate[Key::World5] = sdlstate[SDLK_WORLD_5];
     288    lolstate[Key::World6] = sdlstate[SDLK_WORLD_6];
     289    lolstate[Key::World7] = sdlstate[SDLK_WORLD_7];
     290    lolstate[Key::World8] = sdlstate[SDLK_WORLD_8];
     291    lolstate[Key::World9] = sdlstate[SDLK_WORLD_9];
     292    lolstate[Key::World10] = sdlstate[SDLK_WORLD_10];
     293    lolstate[Key::World11] = sdlstate[SDLK_WORLD_11];
     294    lolstate[Key::World12] = sdlstate[SDLK_WORLD_12];
     295    lolstate[Key::World13] = sdlstate[SDLK_WORLD_13];
     296    lolstate[Key::World14] = sdlstate[SDLK_WORLD_14];
     297    lolstate[Key::World15] = sdlstate[SDLK_WORLD_15];
     298    lolstate[Key::World16] = sdlstate[SDLK_WORLD_16];
     299    lolstate[Key::World17] = sdlstate[SDLK_WORLD_17];
     300    lolstate[Key::World18] = sdlstate[SDLK_WORLD_18];
     301    lolstate[Key::World19] = sdlstate[SDLK_WORLD_19];
     302    lolstate[Key::World20] = sdlstate[SDLK_WORLD_20];
     303    lolstate[Key::World21] = sdlstate[SDLK_WORLD_21];
     304    lolstate[Key::World22] = sdlstate[SDLK_WORLD_22];
     305    lolstate[Key::World23] = sdlstate[SDLK_WORLD_23];
     306    lolstate[Key::World24] = sdlstate[SDLK_WORLD_24];
     307    lolstate[Key::World25] = sdlstate[SDLK_WORLD_25];
     308    lolstate[Key::World26] = sdlstate[SDLK_WORLD_26];
     309    lolstate[Key::World27] = sdlstate[SDLK_WORLD_27];
     310    lolstate[Key::World28] = sdlstate[SDLK_WORLD_28];
     311    lolstate[Key::World29] = sdlstate[SDLK_WORLD_29];
     312    lolstate[Key::World30] = sdlstate[SDLK_WORLD_30];
     313    lolstate[Key::World31] = sdlstate[SDLK_WORLD_31];
     314    lolstate[Key::World32] = sdlstate[SDLK_WORLD_32];
     315    lolstate[Key::World33] = sdlstate[SDLK_WORLD_33];
     316    lolstate[Key::World34] = sdlstate[SDLK_WORLD_34];
     317    lolstate[Key::World35] = sdlstate[SDLK_WORLD_35];
     318    lolstate[Key::World36] = sdlstate[SDLK_WORLD_36];
     319    lolstate[Key::World37] = sdlstate[SDLK_WORLD_37];
     320    lolstate[Key::World38] = sdlstate[SDLK_WORLD_38];
     321    lolstate[Key::World39] = sdlstate[SDLK_WORLD_39];
     322    lolstate[Key::World40] = sdlstate[SDLK_WORLD_40];
     323    lolstate[Key::World41] = sdlstate[SDLK_WORLD_41];
     324    lolstate[Key::World42] = sdlstate[SDLK_WORLD_42];
     325    lolstate[Key::World43] = sdlstate[SDLK_WORLD_43];
     326    lolstate[Key::World44] = sdlstate[SDLK_WORLD_44];
     327    lolstate[Key::World45] = sdlstate[SDLK_WORLD_45];
     328    lolstate[Key::World46] = sdlstate[SDLK_WORLD_46];
     329    lolstate[Key::World47] = sdlstate[SDLK_WORLD_47];
     330    lolstate[Key::World48] = sdlstate[SDLK_WORLD_48];
     331    lolstate[Key::World49] = sdlstate[SDLK_WORLD_49];
     332    lolstate[Key::World50] = sdlstate[SDLK_WORLD_50];
     333    lolstate[Key::World51] = sdlstate[SDLK_WORLD_51];
     334    lolstate[Key::World52] = sdlstate[SDLK_WORLD_52];
     335    lolstate[Key::World53] = sdlstate[SDLK_WORLD_53];
     336    lolstate[Key::World54] = sdlstate[SDLK_WORLD_54];
     337    lolstate[Key::World55] = sdlstate[SDLK_WORLD_55];
     338    lolstate[Key::World56] = sdlstate[SDLK_WORLD_56];
     339    lolstate[Key::World57] = sdlstate[SDLK_WORLD_57];
     340    lolstate[Key::World58] = sdlstate[SDLK_WORLD_58];
     341    lolstate[Key::World59] = sdlstate[SDLK_WORLD_59];
     342    lolstate[Key::World60] = sdlstate[SDLK_WORLD_60];
     343    lolstate[Key::World61] = sdlstate[SDLK_WORLD_61];
     344    lolstate[Key::World62] = sdlstate[SDLK_WORLD_62];
     345    lolstate[Key::World63] = sdlstate[SDLK_WORLD_63];
     346    lolstate[Key::World64] = sdlstate[SDLK_WORLD_64];
     347    lolstate[Key::World65] = sdlstate[SDLK_WORLD_65];
     348    lolstate[Key::World66] = sdlstate[SDLK_WORLD_66];
     349    lolstate[Key::World67] = sdlstate[SDLK_WORLD_67];
     350    lolstate[Key::World68] = sdlstate[SDLK_WORLD_68];
     351    lolstate[Key::World69] = sdlstate[SDLK_WORLD_69];
     352    lolstate[Key::World70] = sdlstate[SDLK_WORLD_70];
     353    lolstate[Key::World71] = sdlstate[SDLK_WORLD_71];
     354    lolstate[Key::World72] = sdlstate[SDLK_WORLD_72];
     355    lolstate[Key::World73] = sdlstate[SDLK_WORLD_73];
     356    lolstate[Key::World74] = sdlstate[SDLK_WORLD_74];
     357    lolstate[Key::World75] = sdlstate[SDLK_WORLD_75];
     358    lolstate[Key::World76] = sdlstate[SDLK_WORLD_76];
     359    lolstate[Key::World77] = sdlstate[SDLK_WORLD_77];
     360    lolstate[Key::World78] = sdlstate[SDLK_WORLD_78];
     361    lolstate[Key::World79] = sdlstate[SDLK_WORLD_79];
     362    lolstate[Key::World80] = sdlstate[SDLK_WORLD_80];
     363    lolstate[Key::World81] = sdlstate[SDLK_WORLD_81];
     364    lolstate[Key::World82] = sdlstate[SDLK_WORLD_82];
     365    lolstate[Key::World83] = sdlstate[SDLK_WORLD_83];
     366    lolstate[Key::World84] = sdlstate[SDLK_WORLD_84];
     367    lolstate[Key::World85] = sdlstate[SDLK_WORLD_85];
     368    lolstate[Key::World86] = sdlstate[SDLK_WORLD_86];
     369    lolstate[Key::World87] = sdlstate[SDLK_WORLD_87];
     370    lolstate[Key::World88] = sdlstate[SDLK_WORLD_88];
     371    lolstate[Key::World89] = sdlstate[SDLK_WORLD_89];
     372    lolstate[Key::World90] = sdlstate[SDLK_WORLD_90];
     373    lolstate[Key::World91] = sdlstate[SDLK_WORLD_91];
     374    lolstate[Key::World92] = sdlstate[SDLK_WORLD_92];
     375    lolstate[Key::World93] = sdlstate[SDLK_WORLD_93];
     376    lolstate[Key::World94] = sdlstate[SDLK_WORLD_94];
     377    lolstate[Key::World95] = sdlstate[SDLK_WORLD_95];
     378
     379    lolstate[Key::KP0] = sdlstate[SDLK_KP0];
     380    lolstate[Key::KP1] = sdlstate[SDLK_KP1];
     381    lolstate[Key::KP2] = sdlstate[SDLK_KP2];
     382    lolstate[Key::KP3] = sdlstate[SDLK_KP3];
     383    lolstate[Key::KP4] = sdlstate[SDLK_KP4];
     384    lolstate[Key::KP5] = sdlstate[SDLK_KP5];
     385    lolstate[Key::KP6] = sdlstate[SDLK_KP6];
     386    lolstate[Key::KP7] = sdlstate[SDLK_KP7];
     387    lolstate[Key::KP8] = sdlstate[SDLK_KP8];
     388    lolstate[Key::KP9] = sdlstate[SDLK_KP9];
     389    lolstate[Key::KPPeriod] = sdlstate[SDLK_KP_PERIOD];
     390    lolstate[Key::KPDivide] = sdlstate[SDLK_KP_DIVIDE];
     391    lolstate[Key::KPMultiply] = sdlstate[SDLK_KP_MULTIPLY];
     392    lolstate[Key::KPMinus] = sdlstate[SDLK_KP_MINUS];
     393    lolstate[Key::KPPlus] = sdlstate[SDLK_KP_PLUS];
     394    lolstate[Key::KPEnter] = sdlstate[SDLK_KP_ENTER];
     395    lolstate[Key::KPEquals] = sdlstate[SDLK_KP_EQUALS];
     396
     397    lolstate[Key::Up] = sdlstate[SDLK_UP];
     398    lolstate[Key::Down] = sdlstate[SDLK_DOWN];
     399    lolstate[Key::Right] = sdlstate[SDLK_RIGHT];
     400    lolstate[Key::Left] = sdlstate[SDLK_LEFT];
     401    lolstate[Key::Insert] = sdlstate[SDLK_INSERT];
     402    lolstate[Key::Home] = sdlstate[SDLK_HOME];
     403    lolstate[Key::End] = sdlstate[SDLK_END];
     404    lolstate[Key::PageUp] = sdlstate[SDLK_PAGEUP];
     405    lolstate[Key::PageDown] = sdlstate[SDLK_PAGEDOWN];
     406
     407    lolstate[Key::F1] = sdlstate[SDLK_F1];
     408    lolstate[Key::F2] = sdlstate[SDLK_F2];
     409    lolstate[Key::F3] = sdlstate[SDLK_F3];
     410    lolstate[Key::F4] = sdlstate[SDLK_F4];
     411    lolstate[Key::F5] = sdlstate[SDLK_F5];
     412    lolstate[Key::F6] = sdlstate[SDLK_F6];
     413    lolstate[Key::F7] = sdlstate[SDLK_F7];
     414    lolstate[Key::F8] = sdlstate[SDLK_F8];
     415    lolstate[Key::F9] = sdlstate[SDLK_F9];
     416    lolstate[Key::F10] = sdlstate[SDLK_F10];
     417    lolstate[Key::F11] = sdlstate[SDLK_F11];
     418    lolstate[Key::F12] = sdlstate[SDLK_F12];
     419    lolstate[Key::F13] = sdlstate[SDLK_F13];
     420    lolstate[Key::F14] = sdlstate[SDLK_F14];
     421    lolstate[Key::F15] = sdlstate[SDLK_F15];
     422
     423    lolstate[Key::NumLock] = sdlstate[SDLK_NUMLOCK];
     424    lolstate[Key::CapsLock] = sdlstate[SDLK_CAPSLOCK];
     425    lolstate[Key::ScrollLock] = sdlstate[SDLK_SCROLLOCK];
     426    lolstate[Key::RightShift] = sdlstate[SDLK_RSHIFT];
     427    lolstate[Key::LeftShift] = sdlstate[SDLK_LSHIFT];
     428    lolstate[Key::RightCtrl] = sdlstate[SDLK_RCTRL];
     429    lolstate[Key::LeftCtrl] = sdlstate[SDLK_LCTRL];
     430    lolstate[Key::RightAlt] = sdlstate[SDLK_RALT];
     431    lolstate[Key::LeftAlt] = sdlstate[SDLK_LALT];
     432    lolstate[Key::RightMeta] = sdlstate[SDLK_RMETA];
     433    lolstate[Key::LeftMeta] = sdlstate[SDLK_LMETA];
     434    lolstate[Key::LeftSuper] = sdlstate[SDLK_LSUPER];
     435    lolstate[Key::RightSuper] = sdlstate[SDLK_RSUPER];
     436    lolstate[Key::Mode] = sdlstate[SDLK_MODE];
     437    lolstate[Key::Compose] = sdlstate[SDLK_COMPOSE];
     438
     439    lolstate[Key::Help] = sdlstate[SDLK_HELP];
     440    lolstate[Key::Print] = sdlstate[SDLK_PRINT];
     441    lolstate[Key::SysReq] = sdlstate[SDLK_SYSREQ];
     442    lolstate[Key::Break] = sdlstate[SDLK_BREAK];
     443    lolstate[Key::Menu] = sdlstate[SDLK_MENU];
     444    lolstate[Key::Power] = sdlstate[SDLK_POWER];
     445    lolstate[Key::Euro] = sdlstate[SDLK_EURO];
     446    lolstate[Key::Undo] = sdlstate[SDLK_UNDO];
     447
    206448    UNUSED(seconds);
    207 #endif
    208449#endif
    209450}
Note: See TracChangeset for help on using the changeset viewer.