wxKeyboardState Class Reference
[Events]

#include <wx/kbdstate.h>

Inheritance diagram for wxKeyboardState:
Inheritance graph
[legend]

Detailed Description

Provides methods for testing the state of the keyboard modifier keys.

This class is used as a base class of wxKeyEvent and wxMouseState and, hence, indirectly, of wxMouseEvent, 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 <wx/kbdstate.h> and thus has no linking requirements.

Library:  None; this class implementation is entirely header-based.
Category:  Events
See also:
wxKeyEvent, wxMouseState

Public Member Functions

 wxKeyboardState (bool controlDown=false, bool shiftDown=false, bool altDown=false, bool metaDown=false)
 Constructor initializes the modifier key settings.
int GetModifiers () const
 Return the bit mask of all pressed modifier keys.
bool HasModifiers () const
 Returns true if any modifiers at all are pressed.
bool ControlDown () const
 Returns true if the Control key is pressed.
bool ShiftDown () const
 Returns true if the Shift key is pressed.
bool MetaDown () const
 Returns true if the Meta/Windows/Apple key is pressed.
bool AltDown () const
 Returns true if the Alt key is pressed.
bool CmdDown () const
 Returns true if the key used for command accelerators is pressed.

List of all members.


Constructor & Destructor Documentation

wxKeyboardState::wxKeyboardState ( bool  controlDown = false,
bool  shiftDown = false,
bool  altDown = false,
bool  metaDown = false 
)

Constructor initializes the modifier key settings.

By default, no modifiers are active.


Member Function Documentation

bool wxKeyboardState::AltDown (  )  const

Returns true if the Alt key is pressed.

Notice that GetModifiers() should usually be used instead of this one.

bool wxKeyboardState::CmdDown (  )  const

Returns true if the key used for command accelerators is pressed.

Cmd is a pseudo key which is Control for PC and Unix platforms but Apple (or Command) key under Macs: it makes often sense to use it instead of ControlDown() because Command key is used for the same thing under Mac as Control elsewhere (even though Control still exists, it is usually not used for the same purpose under Mac).

Notice that GetModifiers() should usually be used instead of this one.

bool wxKeyboardState::ControlDown (  )  const

Returns true if the Control key is pressed.

This function doesn't distinguish between right and left control keys.

In portable code you usually want to use CmdDown() to automatically test for the more frequently used Command key (and not the rarely used Control one) under Mac.

Notice that GetModifiers() should usually be used instead of this one.

int wxKeyboardState::GetModifiers (  )  const

Return the bit mask of all pressed modifier keys.

The return value is a combination of wxMOD_ALT, wxMOD_CONTROL, wxMOD_SHIFT and wxMOD_META bit masks. Additionally, wxMOD_NONE is defined as 0, i.e. corresponds to no modifiers (see HasModifiers()) and wxMOD_CMD is either wxMOD_CONTROL (MSW and Unix) or wxMOD_META (Mac), see CmdDown(). See wxKeyModifier for the full list of modifiers.

Notice that this function is easier to use correctly than, for example, ControlDown() because when using the latter you also have to remember to test that none of the other modifiers is pressed:

        if ( ControlDown() && !AltDown() && !ShiftDown() && !MetaDown() )
            ... 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 ( GetModifiers() == wxMOD_CONTROL )
            ... handle Ctrl-XXX ...

with this function.

bool wxKeyboardState::HasModifiers (  )  const

Returns true if any modifiers at all are pressed.

This is equivalent to GetModifiers() != wxMOD_NONE.

bool wxKeyboardState::MetaDown (  )  const

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 and Apple, or Command, key under Mac.

Notice that GetModifiers() should usually be used instead of this one.

See also:
CmdDown()

Reimplemented in wxMouseEvent.

bool wxKeyboardState::ShiftDown (  )  const

Returns true if the Shift key is pressed.

This function doesn't distinguish between right and left shift keys.

Notice that GetModifiers() should usually be used instead of this one.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines



wxWidgets logo

[ top ]