/src/ois/includes/linux/LinuxKeyboard.h

https://bitbucket.org/cabalistic/ogredeps/ · C Header · 98 lines · 46 code · 18 blank · 34 comment · 6 complexity · c5a617987186b8cb8f8c2fd2931ea446 MD5 · raw file

  1. /*
  2. The zlib/libpng License
  3. Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
  4. This software is provided 'as-is', without any express or implied warranty. In no event will
  5. the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose, including commercial
  7. applications, and to alter it and redistribute it freely, subject to the following
  8. restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that
  10. you wrote the original software. If you use this software in a product,
  11. an acknowledgment in the product documentation would be appreciated but is
  12. not required.
  13. 2. Altered source versions must be plainly marked as such, and must not be
  14. misrepresented as being the original software.
  15. 3. This notice may not be removed or altered from any source distribution.
  16. */
  17. #ifndef _LINUX_KEYBOARD_H_EADER_
  18. #define _LINUX_KEYBOARD_H_EADER_
  19. #include "linux/LinuxPrereqs.h"
  20. #include "OISKeyboard.h"
  21. #include <X11/Xlib.h>
  22. namespace OIS
  23. {
  24. /** Linux implementation of Keyboard object - uses x11 */
  25. class LinuxKeyboard : public Keyboard
  26. {
  27. public:
  28. LinuxKeyboard(InputManager* creator, bool buffered, bool grab);
  29. virtual ~LinuxKeyboard();
  30. /** @copydoc Keyboard::isKeyDown */
  31. virtual bool isKeyDown( KeyCode key ) const;
  32. /** @copydoc Keyboard::getAsString */
  33. virtual const std::string& getAsString( KeyCode kc );
  34. /** @copydoc Keyboard::copyKeyStates */
  35. virtual void copyKeyStates( char keys[256] ) const;
  36. /** @copydoc Object::setBuffered */
  37. virtual void setBuffered(bool buffered);
  38. /** @copydoc Object::capture */
  39. virtual void capture();
  40. /** @copydoc Object::queryInterface */
  41. virtual Interface* queryInterface(Interface::IType) {return 0;}
  42. /** @copydoc Object::_initialize */
  43. virtual void _initialize();
  44. protected:
  45. inline bool _isKeyRepeat(XEvent &event)
  46. {
  47. //When a key is repeated, there will be two events: released, followed by another immediate pressed. So check to see if another pressed is present
  48. if(!XPending(display))
  49. return false;
  50. XEvent e;
  51. XPeekEvent(display, &e);
  52. if(e.type == KeyPress && e.xkey.keycode == event.xkey.keycode && (e.xkey.time - event.xkey.time) < 2)
  53. {
  54. XNextEvent(display, &e);
  55. return true;
  56. }
  57. return false;
  58. }
  59. bool _injectKeyDown( KeySym key, int text );
  60. bool _injectKeyUp( KeySym key );
  61. //! 1:1 Conversion Map between X Key Events and OIS KeyCodes
  62. typedef std::map<KeySym, KeyCode> XtoOIS_KeyMap;
  63. XtoOIS_KeyMap keyConversion;
  64. //! Depressed Key List
  65. char KeyBuffer[256];
  66. //! X11 Stuff
  67. Window window;
  68. Display *display;
  69. bool grabKeyboard;
  70. bool keyFocusLost;
  71. std::string mGetString;
  72. };
  73. }
  74. #endif //_LINUX_KEYBOARD_H_EADER_