| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- /*
- * This source file is part of RmlUi, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://github.com/mikke89/RmlUi
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- * Copyright (c) 2019 The RmlUi Team, and contributors
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
- #include <Input.h>
- /**
- This map contains 4 different mappings from key identifiers to character codes. Each entry represents a different
- combination of shift and capslock state.
- */
- char ascii_map[4][51] =
- {
- // shift off and capslock off
- {
- 0,
- ' ',
- '0',
- '1',
- '2',
- '3',
- '4',
- '5',
- '6',
- '7',
- '8',
- '9',
- 'a',
- 'b',
- 'c',
- 'd',
- 'e',
- 'f',
- 'g',
- 'h',
- 'i',
- 'j',
- 'k',
- 'l',
- 'm',
- 'n',
- 'o',
- 'p',
- 'q',
- 'r',
- 's',
- 't',
- 'u',
- 'v',
- 'w',
- 'x',
- 'y',
- 'z',
- ';',
- '=',
- ',',
- '-',
- '.',
- '/',
- '`',
- '[',
- '\\',
- ']',
- '\'',
- 0,
- 0
- },
- // shift on and capslock off
- {
- 0,
- ' ',
- ')',
- '!',
- '@',
- '#',
- '$',
- '%',
- '^',
- '&',
- '*',
- '(',
- 'A',
- 'B',
- 'C',
- 'D',
- 'E',
- 'F',
- 'G',
- 'H',
- 'I',
- 'J',
- 'K',
- 'L',
- 'M',
- 'N',
- 'O',
- 'P',
- 'Q',
- 'R',
- 'S',
- 'T',
- 'U',
- 'V',
- 'W',
- 'X',
- 'Y',
- 'Z',
- ':',
- '+',
- '<',
- '_',
- '>',
- '?',
- '~',
- '{',
- '|',
- '}',
- '"',
- 0,
- 0
- },
- // shift on and capslock on
- {
- 0,
- ' ',
- ')',
- '!',
- '@',
- '#',
- '$',
- '%',
- '^',
- '&',
- '*',
- '(',
- 'a',
- 'b',
- 'c',
- 'd',
- 'e',
- 'f',
- 'g',
- 'h',
- 'i',
- 'j',
- 'k',
- 'l',
- 'm',
- 'n',
- 'o',
- 'p',
- 'q',
- 'r',
- 's',
- 't',
- 'u',
- 'v',
- 'w',
- 'x',
- 'y',
- 'z',
- ':',
- '+',
- '<',
- '_',
- '>',
- '?',
- '~',
- '{',
- '|',
- '}',
- '"',
- 0,
- 0
- },
- // shift off and capslock on
- {
- 0,
- ' ',
- '1',
- '2',
- '3',
- '4',
- '5',
- '6',
- '7',
- '8',
- '9',
- '0',
- 'A',
- 'B',
- 'C',
- 'D',
- 'E',
- 'F',
- 'G',
- 'H',
- 'I',
- 'J',
- 'K',
- 'L',
- 'M',
- 'N',
- 'O',
- 'P',
- 'Q',
- 'R',
- 'S',
- 'T',
- 'U',
- 'V',
- 'W',
- 'X',
- 'Y',
- 'Z',
- ';',
- '=',
- ',',
- '-',
- '.',
- '/',
- '`',
- '[',
- '\\',
- ']',
- '\'',
- 0,
- 0
- }
- };
- char keypad_map[2][18] =
- {
- {
- '0',
- '1',
- '2',
- '3',
- '4',
- '5',
- '6',
- '7',
- '8',
- '9',
- '\n',
- '*',
- '+',
- 0,
- '-',
- '.',
- '/',
- '='
- },
- {
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- '\n',
- '*',
- '+',
- 0,
- '-',
- 0,
- '/',
- '='
- }
- };
- Rml::Core::Context* Input::context = nullptr;
- // Sets the context to send input events to.
- void Input::SetContext(Rml::Core::Context* _context)
- {
- context = _context;
- }
- // Returns the character code for a key identifer / key modifier combination.
- Rml::Core::Character Input::GetCharacterCode(Rml::Core::Input::KeyIdentifier key_identifier, int key_modifier_state)
- {
- using Rml::Core::Character;
- // Check if we have a keycode capable of generating characters on the main keyboard (ie, not on the numeric
- // keypad; that is dealt with below).
- if (key_identifier <= Rml::Core::Input::KI_OEM_102)
- {
- // Get modifier states
- bool shift = (key_modifier_state & Rml::Core::Input::KM_SHIFT) > 0;
- bool capslock = (key_modifier_state & Rml::Core::Input::KM_CAPSLOCK) > 0;
- // Return character code based on identifier and modifiers
- if (shift && !capslock)
- return (Character)ascii_map[1][key_identifier];
- if (shift && capslock)
- return (Character)ascii_map[2][key_identifier];
- if (!shift && capslock)
- return (Character)ascii_map[3][key_identifier];
- return (Character)ascii_map[0][key_identifier];
- }
- // Check if we have a keycode from the numeric keypad.
- else if (key_identifier <= Rml::Core::Input::KI_OEM_NEC_EQUAL)
- {
- if (key_modifier_state & Rml::Core::Input::KM_NUMLOCK)
- return (Character)keypad_map[0][key_identifier - Rml::Core::Input::KI_NUMPAD0];
- else
- return (Character)keypad_map[1][key_identifier - Rml::Core::Input::KI_NUMPAD0];
- }
- else if (key_identifier == Rml::Core::Input::KI_RETURN)
- return (Character)'\n';
- return Character::Null;
- }
|