PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PlatformKeyboard Class Reference

#include <PlatformKeyboard.h>

Inheritance diagram for PlatformKeyboard:
PKeyboard PEBLObjectBase PKeyboard PDevice PDevice

Public Member Functions

 PlatformKeyboard ()
 Standard Constructor.
 
virtual ~PlatformKeyboard ()
 Standard Destructor.
 
virtual PEBL_Keycode IsKeyDown (PEBL_Keycode key) const
 Primitive key event poller.
 
virtual bool IsKeyUp (PEBL_Keycode key) const
 
virtual int GetState (int iface) const
 
 PlatformKeyboard ()
 
virtual ~PlatformKeyboard ()
 
virtual PEBL_Keycode IsKeyDown (PEBL_Keycode code) const
 
virtual bool IsKeyUp (PEBL_Keycode code) const
 
- Public Member Functions inherited from PKeyboard
 PKeyboard ()
 The Standard constructor.

 
virtual ~PKeyboard ()
 The Standard destructor.

 
virtual PEBL_Keycode TranslateString (std::string letter) const
 Translate a letter string to the appropriate keyboard symbol.
 
virtual std::string TranslateKeyCode (const PEBL_Keycode code) const
 
virtual PEBL_DEVICE_TYPE GetDeviceType ()
 
virtual int GetModKeys () const
 
- Public Member Functions inherited from PDevice
 PDevice ()
 The Standard constructor.
 
virtual ~PDevice ()
 The Standard destructor.
 
- Public Member Functions inherited from PEBLObjectBase
 PEBLObjectBase ()
 Standard Constructor.
 
 PEBLObjectBase (ComplexDataType cdt)
 Standard Constructor.
 
 PEBLObjectBase (const PEBLObjectBase &pob)
 
virtual ~PEBLObjectBase ()
 Standard Destructor.
 
virtual bool InitializeProperty (std::string name, Variant v)
 
virtual bool SetProperty (std::string name, Variant v)
 
Variant GetProperty (std::string) const
 
virtual ObjectValidationError ValidateProperty (std::string, Variant v) const
 
virtual ObjectValidationError ValidateProperty (std::string) const
 
ComplexDataType GetType ()
 
virtual std::string ObjectName () const
 
virtual std::ostream & PrintProperties (std::ostream &out)
 
virtual Variant GetPropertyList ()
 

Protected Member Functions

virtual std::ostream & SendToStream (std::ostream &out) const
 
virtual std::ostream & SendToStream (std::ostream &out) const
 

Additional Inherited Members

- Protected Attributes inherited from PEBLObjectBase
ComplexDataType mCDT
 
std::map< std::string, VariantmProperties
 

Detailed Description

This class instantiates a Keyboard event handler using platform-specific code.

Definition at line 42 of file sdl/PlatformKeyboard.h.

Constructor & Destructor Documentation

◆ PlatformKeyboard() [1/2]

PlatformKeyboard::PlatformKeyboard ( )

Standard Constructor.

This is the SDL-specific binding for the keyboard handler. SDL key events can be accessed in multiple ways. First, they can be handled through the standard SDL event queue. Key-Up and Key-Down events are signalled through this loop. Also, the entire state of the keyboard can be polled at a given point in time, and this state can be examined. For optimal performance, we should select a subset of keys to examine and poll them until one flips.

Definition at line 59 of file sdl/PlatformKeyboard.cpp.

61{
62
63 //EMSCRIPTEN uses sdl 2, which replaces getkeystat with getkeyboardstate
64#if defined PEBL_EMSCRIPTEN
65 mKeyboardState = SDL_GetKeyboardState(NULL);
66 SDL_PumpEvents();
67#else
68 mKeyboardState = SDL_GetKeyboardState(NULL);
69 SDL_PumpEvents();
70#endif
71}
#define NULL
Definition BinReloc.cpp:317

References NULL.

◆ ~PlatformKeyboard() [1/2]

PlatformKeyboard::~PlatformKeyboard ( )
virtual

Standard Destructor.

Definition at line 75 of file sdl/PlatformKeyboard.cpp.

76{
77
78}

◆ PlatformKeyboard() [2/2]

PlatformKeyboard::PlatformKeyboard ( )

◆ ~PlatformKeyboard() [2/2]

virtual PlatformKeyboard::~PlatformKeyboard ( )
virtual

Member Function Documentation

◆ GetState()

int PlatformKeyboard::GetState ( int  iface) const
virtual

Reimplemented from PKeyboard.

Definition at line 212 of file sdl/PlatformKeyboard.cpp.

213{
214
215 //This asks for the state of a particular key.
216
217
218 PEBL_Keycode key = (PEBL_Keycode)iface;
219 int ret = (int)IsKeyUp(key);
220
221 //cout << "keyboard Getstating: " << PEBL_KEYCODE_x <<":"<<iface <<"|" << ret << endl;
222 return ret;
223}
PEBL_Keycode
Definition PKeyboard.h:78
virtual bool IsKeyUp(PEBL_Keycode key) const

References IsKeyUp().

◆ IsKeyDown() [1/2]

virtual PEBL_Keycode PlatformKeyboard::IsKeyDown ( PEBL_Keycode  code) const
virtual

This will test whether a specific key is down, and return true if it is.

Implements PKeyboard.

◆ IsKeyDown() [2/2]

PEBL_Keycode PlatformKeyboard::IsKeyDown ( PEBL_Keycode  key) const
virtual

Primitive key event poller.

This will test whether a specific key is down, and return true if it is.

Implements PKeyboard.

Definition at line 85 of file sdl/PlatformKeyboard.cpp.

86{
87 if(key == PEBL_KEYCODE_ANYKEY)
88 {
89
90
91 return IsAnyKeyDown();
92 }
93 else
94 {
95
96
97 SDL_PumpEvents();
98 if( mKeyboardState[key] == 1)
99 return key;
100 else
102
103 }
104}
@ PEBL_KEYCODE_ANYKEY
Definition PKeyboard.h:329
@ PEBL_KEYCODE_NOTHING
Definition PKeyboard.h:331

References PEBL_KEYCODE_ANYKEY, and PEBL_KEYCODE_NOTHING.

Referenced by PEBLEnvironment::IsAnyKeyDown(), and PEBLEnvironment::IsKeyDown().

◆ IsKeyUp() [1/2]

virtual bool PlatformKeyboard::IsKeyUp ( PEBL_Keycode  code) const
virtual

This will test whether a specific key is up, and return true if it is.

Implements PKeyboard.

◆ IsKeyUp() [2/2]

bool PlatformKeyboard::IsKeyUp ( PEBL_Keycode  key) const
virtual

This will test whether a specific key is up, and return true if it is.

Primitive key event poller for 'up' state. If the key argument is the 'anykey' it will return true if every key is unpressed. we want to bo able to return the value of the key pressed, thus determining which key was pressed when anykey is being tested.

Implements PKeyboard.

Definition at line 113 of file sdl/PlatformKeyboard.cpp.

114{
115
116 //cout << "Testing for iskeyup: " << key << "|" << PEBL_KEYCODE_ANYKEY << endl;
117
118 //If the key is 'anykey', what you are really asking is if there
119 //are any keys that are not up. This is a semantic distortion, because
120 //logically, you should be asking whether ALL keys are pressed, which
121 //is pretty ridiculous.
122 //
123 if(key == PEBL_KEYCODE_ANYKEY)
124 {
125 PEBL_Keycode key = IsAnyKeyDown();
126
127 return key;
128 }
129 else
130 {
131 //SDL_PumpEvents();
132 //cout << "Getting scancode name from key: " << key << endl;
133 int code = SDL_GetScancodeFromKey(key);
134 //cout << code << "---------" << endl;
135 if(mKeyboardState[code]==1)
136 return key;
137 else
138 return PEBL_KEYCODE_NOTHING; //==0==false
139 }
140}

References PEBL_KEYCODE_ANYKEY, and PEBL_KEYCODE_NOTHING.

Referenced by GetState(), and PEBLEnvironment::IsKeyUp().

◆ SendToStream() [1/2]

std::ostream & PlatformKeyboard::SendToStream ( std::ostream &  out) const
protectedvirtual

Reimplemented from PKeyboard.

Definition at line 15 of file validator/PlatformKeyboard.cpp.

15 {
16 out << "PlatformKeyboard (validator)";
17 return out;
18}

◆ SendToStream() [2/2]

virtual std::ostream & PlatformKeyboard::SendToStream ( std::ostream &  out) const
protectedvirtual

Reimplemented from PKeyboard.


The documentation for this class was generated from the following files: