kbdstate.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/kbdstate.h
  3. // Purpose: documentation of wxKeyboardState
  4. // Author: wxWidgets team
  5. // Created: 2008-09-19
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. /**
  9. Provides methods for testing the state of the keyboard modifier keys.
  10. This class is used as a base class of wxKeyEvent and wxMouseState and,
  11. hence, indirectly, of wxMouseEvent, so its methods may be used to get
  12. information about the modifier keys which were pressed when the event
  13. occurred.
  14. This class is implemented entirely inline in @<wx/kbdstate.h@> and thus has
  15. no linking requirements.
  16. @nolibrary
  17. @category{events}
  18. @see wxKeyEvent, wxMouseState
  19. */
  20. class wxKeyboardState
  21. {
  22. public:
  23. /**
  24. Constructor initializes the modifier key settings.
  25. By default, no modifiers are active.
  26. */
  27. wxKeyboardState(bool controlDown = false,
  28. bool shiftDown = false,
  29. bool altDown = false,
  30. bool metaDown = false);
  31. /**
  32. Return the bit mask of all pressed modifier keys.
  33. The return value is a combination of @c wxMOD_ALT, @c wxMOD_CONTROL,
  34. @c wxMOD_SHIFT and @c wxMOD_META bit masks. Additionally, @c wxMOD_NONE
  35. is defined as 0, i.e. corresponds to no modifiers (see HasAnyModifiers())
  36. and @c wxMOD_CMD is either @c wxMOD_CONTROL (MSW and Unix) or
  37. @c wxMOD_META (Mac), see CmdDown().
  38. See ::wxKeyModifier for the full list of modifiers.
  39. Notice that this function is easier to use correctly than, for example,
  40. ControlDown() because when using the latter you also have to remember to
  41. test that none of the other modifiers is pressed:
  42. @code
  43. if ( ControlDown() && !AltDown() && !ShiftDown() && !MetaDown() )
  44. ... handle Ctrl-XXX ...
  45. @endcode
  46. and forgetting to do it can result in serious program bugs (e.g. program
  47. not working with European keyboard layout where @c AltGr key which is
  48. seen by the program as combination of CTRL and ALT is used). On the
  49. other hand, you can simply write:
  50. @code
  51. if ( GetModifiers() == wxMOD_CONTROL )
  52. ... handle Ctrl-XXX ...
  53. @endcode
  54. with this function.
  55. */
  56. int GetModifiers() const;
  57. /**
  58. Returns true if any modifiers at all are pressed.
  59. This is equivalent to @c GetModifiers() @c != @c wxMOD_NONE.
  60. Notice that this is different from HasModifiers() method which doesn't
  61. take e.g. Shift modifier into account. This method is most suitable for
  62. mouse events when any modifier, including Shift, can change the
  63. interpretation of the event.
  64. @since 2.9.5
  65. */
  66. bool HasAnyModifiers() const;
  67. /**
  68. Returns true if Control or Alt are pressed.
  69. Checks if Control, Alt or, under OS X only, Command key are pressed
  70. (notice that the real Control key is still taken into account under OS
  71. X too).
  72. This method returns @false if only Shift is pressed for compatibility
  73. reasons and also because pressing Shift usually doesn't change the
  74. interpretation of key events, see HasAnyModifiers() if you want to
  75. take Shift into account as well.
  76. */
  77. bool HasModifiers() const;
  78. /**
  79. Returns true if the Control key or Apple/Command key under OS X is pressed.
  80. This function doesn't distinguish between right and left control keys.
  81. Notice that GetModifiers() should usually be used instead of this one.
  82. */
  83. bool ControlDown() const;
  84. /**
  85. Returns true if the Control key (also under OS X).
  86. This function doesn't distinguish between right and left control keys.
  87. Notice that GetModifiers() should usually be used instead of this one.
  88. */
  89. bool RawControlDown() const;
  90. /**
  91. Returns true if the Shift key is pressed.
  92. This function doesn't distinguish between right and left shift keys.
  93. Notice that GetModifiers() should usually be used instead of this one.
  94. */
  95. bool ShiftDown() const;
  96. /**
  97. Returns true if the Meta/Windows/Apple key is pressed.
  98. This function tests the state of the key traditionally called Meta
  99. under Unix systems, Windows keys under MSW
  100. Notice that GetModifiers() should usually be used instead of this one.
  101. @see CmdDown()
  102. */
  103. bool MetaDown() const;
  104. /**
  105. Returns true if the Alt key is pressed.
  106. Notice that GetModifiers() should usually be used instead of this one.
  107. */
  108. bool AltDown() const;
  109. /**
  110. Returns true if the key used for command accelerators is pressed. Same as
  111. ControlDown(). Deprecated.
  112. Notice that GetModifiers() should usually be used instead of this one.
  113. */
  114. bool CmdDown() const;
  115. void SetControlDown(bool down);
  116. void SetRawControlDown(bool down);
  117. void SetShiftDown(bool down);
  118. void SetAltDown(bool down);
  119. void SetMetaDown(bool down);
  120. };