Class: Wx::KeyboardState
- Inherits:
-
Object
- Object
- Wx::KeyboardState
- Defined in:
- lib/wx/doc/gen/keyboard_state.rb
Overview
This class is untracked and should not be derived from nor instances extended!
Provides methods for testing the state of the keyboard modifier keys.
This class is used as a base class of KeyEvent and MouseState and, hence, indirectly, of MouseEvent, so its methods may be used to get information about the modifier keys which were pressed when the event occurred. This class is implemented entirely inline in </kbdstate.h> and thus has no linking requirements.
Category: Events
Direct Known Subclasses
Instance Method Summary collapse
-
#alt_down ⇒ Boolean
Returns true if the Alt key is pressed.
-
#cmd_down ⇒ Boolean
Returns true if the key used for command accelerators is pressed.
-
#control_down ⇒ Boolean
Returns true if the Control key or Apple/Command key under macOS is pressed.
-
#get_modifiers ⇒ Integer
(also: #modifiers)
Return the bit mask of all pressed modifier keys.
-
#has_any_modifiers ⇒ Boolean
(also: #has_any_modifiers?)
Returns true if any modifiers at all are pressed.
-
#has_modifiers ⇒ Boolean
(also: #has_modifiers?)
Returns true if Control or Alt are pressed.
-
#initialize(controlDown = false, shiftDown = false, altDown = false, metaDown = false) ⇒ Wx::KeyboardState
constructor
Constructor initializes the modifier key settings.
-
#meta_down ⇒ Boolean
Returns true if the Meta/Windows/Apple key is pressed.
-
#raw_control_down ⇒ Boolean
Returns true if the Control key (also under macOS).
- #set_alt_down(down) ⇒ void (also: #alt_down=)
- #set_control_down(down) ⇒ void (also: #control_down=)
- #set_meta_down(down) ⇒ void (also: #meta_down=)
- #set_raw_control_down(down) ⇒ void (also: #raw_control_down=)
- #set_shift_down(down) ⇒ void (also: #shift_down=)
-
#shift_down ⇒ Boolean
Returns true if the Shift key is pressed.
Constructor Details
#initialize(controlDown = false, shiftDown = false, altDown = false, metaDown = false) ⇒ Wx::KeyboardState
Constructor initializes the modifier key settings.
By default, no modifiers are active.
31 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 31 def initialize(controlDown=false, shiftDown=false, altDown=false, =false) end |
Instance Method Details
#alt_down ⇒ Boolean
Returns true if the Alt key is pressed.
Notice that #get_modifiers should usually be used instead of this one.
103 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 103 def alt_down; end |
#cmd_down ⇒ Boolean
Returns true if the key used for command accelerators is pressed.
Same as #control_down. Deprecated. Notice that #get_modifiers should usually be used instead of this one.
110 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 110 def cmd_down; end |
#control_down ⇒ Boolean
Returns true if the Control key or Apple/Command key under macOS is pressed.
This function doesn’t distinguish between right and left control keys. Notice that #get_modifiers should usually be used instead of this one.
76 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 76 def control_down; end |
#get_modifiers ⇒ Integer Also known as: modifiers
Return the bit mask of all pressed modifier keys.
The return value is a combination of Wx::KeyModifier::MOD_ALT, Wx::KeyModifier::MOD_CONTROL, Wx::KeyModifier::MOD_SHIFT and Wx::KeyModifier::MOD_META bit masks. Additionally, Wx::KeyModifier::MOD_NONE is defined as 0, i.e. corresponds to no modifiers (see #has_any_modifiers) and Wx::KeyModifier::MOD_CMD is either Wx::KeyModifier::MOD_CONTROL (MSW and Unix) or Wx::KeyModifier::MOD_META (Mac), see #cmd_down. See Wx::KeyModifier for the full list of modifiers. Notice that this function is easier to use correctly than, for example, #control_down because when using the latter you also have to remember to test that none of the other modifiers is pressed:
if control_down && !alt_down && !shift_down && !meta_down
... handle Ctrl-XXX ...
and forgetting to do it can result in serious program bugs (e.g. program not working with European keyboard layout where AltGr key which is seen by the program as combination of CTRL and ALT is used). On the other hand, you can simply write:
if get_modifiers == Wx::MOD_CONTROL
... handle Ctrl-XXX ...
with this function.
52 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 52 def get_modifiers; end |
#has_any_modifiers ⇒ Boolean Also known as: has_any_modifiers?
Returns true if any modifiers at all are pressed.
This is equivalent to get_modifiers
!=
Wx::KeyModifier::MOD_NONE. Notice that this is different from #has_modifiers method which doesn’t take e.g. Shift modifier into account. This method is most suitable for mouse events when any modifier, including Shift, can change the interpretation of the event.
60 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 60 def has_any_modifiers; end |
#has_modifiers ⇒ Boolean Also known as: has_modifiers?
Returns true if Control or Alt are pressed.
Checks if Control, Alt or, under macOS only, Command key are pressed (notice that the real Control key is still taken into account under OS X too). This method returns false if only Shift is pressed for compatibility reasons and also because pressing Shift usually doesn’t change the interpretation of key events, see #has_any_modifiers if you want to take Shift into account as well.
68 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 68 def has_modifiers; end |
#meta_down ⇒ Boolean
Returns true if the Meta/Windows/Apple key is pressed.
This function tests the state of the key traditionally called Meta under Unix systems, Windows keys under MSW Notice that #get_modifiers should usually be used instead of this one.
97 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 97 def ; end |
#raw_control_down ⇒ Boolean
Returns true if the Control key (also under macOS).
This function doesn’t distinguish between right and left control keys. Notice that #get_modifiers should usually be used instead of this one.
83 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 83 def raw_control_down; end |
#set_alt_down(down) ⇒ void Also known as: alt_down=
This method returns an undefined value.
129 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 129 def set_alt_down(down) end |
#set_control_down(down) ⇒ void Also known as: control_down=
This method returns an undefined value.
114 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 114 def set_control_down(down) end |
#set_meta_down(down) ⇒ void Also known as: meta_down=
This method returns an undefined value.
134 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 134 def (down) end |
#set_raw_control_down(down) ⇒ void Also known as: raw_control_down=
This method returns an undefined value.
119 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 119 def set_raw_control_down(down) end |
#set_shift_down(down) ⇒ void Also known as: shift_down=
This method returns an undefined value.
124 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 124 def set_shift_down(down) end |
#shift_down ⇒ Boolean
Returns true if the Shift key is pressed.
This function doesn’t distinguish between right and left shift keys. Notice that #get_modifiers should usually be used instead of this one.
90 |
# File 'lib/wx/doc/gen/keyboard_state.rb', line 90 def shift_down; end |