OpenBarnyard
 
Loading...
Searching...
No Matches
TInputDXDeviceKeyboard Class Reference

#include <TInputDeviceKeyboard_Win.h>

Inheritance diagram for TInputDXDeviceKeyboard:
TInputDeviceKeyboard TInputDevice TObject TNodeList< T >::TNode

Classes

struct  KeyInfo
 

Public Member Functions

 TDECLARE_CLASS (TInputDXDeviceKeyboard, TInputDeviceKeyboard)
 
 TInputDXDeviceKeyboard ()
 
virtual TBOOL Acquire () override
 
virtual TBOOL Unacquire () override
 
virtual void Release () override
 
virtual void Update (float deltaTime) override
 
virtual TBOOL Flush () override
 
virtual TINT ProcessEvents (TEmitter< TInputInterface, TInputInterface::InputEvent > &emitter, float deltaTime) override
 
virtual TINT GetButtonCount () const override
 
virtual TBOOL IsDown (TINT doodad) const override
 
virtual TBOOL IsEnabled () const override
 
virtual TBOOL IsShiftDown () const override
 
virtual TBOOL IsControlDown () const override
 
virtual TBOOL IsAltDown () const override
 
virtual TBOOL WasDown (TINT doodad) const override
 
virtual TWCHARTranslateDoodadToCharacter (TINT doodad) const override
 
virtual TBOOL Initialise ()
 
virtual TBOOL Deinitialise ()
 
virtual void RefreshDirect ()
 
const TBOOL BindToDIDevice (HWND a_hMainWindow, LPCDIDEVICEINSTANCEA a_poDeviceInstance, IDirectInputDevice8A *a_poDXInputDevice)
 
- Public Member Functions inherited from TInputDeviceKeyboard
 TDECLARE_CLASS (TInputDeviceKeyboard, TInputDevice)
 
 TInputDeviceKeyboard ()
 
 ~TInputDeviceKeyboard ()
 
virtual TBOOL GetDoodadProperties (Doodad a_iDoodad, DoodadProperties &doodadProps) const override
 
virtual TINT GetAxisCount () const override
 
virtual const TCHARGetButtonFromDoodad (Doodad a_iDoodad) const override
 
virtual TINT GetAxisInt (Doodad a_iDoodad, TINT axis) const override
 
virtual float GetAxisFloat (Doodad a_iDoodad, TINT axis) const override
 
virtual TINT ProcessVirtualButtons (EventEmitter &a_rEmitter, TFLOAT flt)
 
void SetVirtStickDoodads (TINT a_iMapID, Doodad a_iDoodad1, Doodad a_iDoodad2, Doodad a_iDoodad3, Doodad a_iDoodad4)
 
void GetVirtStickDoodads (TINT a_iMapID, Doodad &a_rDoodad1, Doodad &a_rDoodad2, Doodad &a_rDoodad3, Doodad &a_rDoodad4)
 
- Public Member Functions inherited from TInputDevice
 TDECLARE_CLASS (TInputDevice, TObject)
 
 TInputDevice ()
 
 ~TInputDevice ()=default
 
virtual TBOOL StartRepeat (Doodad a_iDoodad, TFLOAT a_fFirstRepeatTime, TFLOAT a_fRepeatTime)
 
virtual void StopRepeat (Doodad a_iDoodad)
 
virtual void StopAllRepeats ()
 
virtual TBOOL IsForceFeedbackDevice ()
 
virtual TINT GetAxisInt2 (Doodad a_iDoodad, TINT axis) const
 
virtual TFLOAT GetAxisFloat2 (Doodad a_iDoodad, TINT axis) const
 
virtual void ThrowRepeatEvent (EventEmitter &emitter, RepeatInfo *repeatInfo, TFLOAT deltaTime)
 
TBOOL IsAcquired () const
 
void SetAcquired (TBOOL a_bAcquired)
 
TInputInterfaceGetInputInterface ()
 
void SetInputInterface (TInputInterface *a_pInterface)
 
- Public Member Functions inherited from TObject
virtual Toshi::TClass * GetClass ()
 
virtual void Delete ()
 
virtual ~TObject ()
 
TBOOL IsExactly (TClass *a_pClass)
 
TBOOL IsA (TClass *a_pClass)
 
- Public Member Functions inherited from TNodeList< T >::TNode
constexpr TNode ()
 
constexpr TNode (const TNode &a_rcNode)
 
 TNode (TNode &&a_rNode)
 
T * Next () const
 
T * Prev () const
 
void Remove ()
 
void SetList (TNodeList *list)
 
TNodeListGetList () const
 
TBOOL IsLinked () const
 

Static Public Member Functions

static BOOL CALLBACK EnumObjectCallback (LPCDIDEVICEOBJECTINSTANCEA a_poObjectInstance, LPVOID a_pvRef)
 
- Static Public Member Functions inherited from TInputDevice
static TInputDevice ** GetRegisteredDevices ()
 
static TUINT GetNumRegisteredDevices ()
 
- Static Public Member Functions inherited from TObject
static Toshi::TObject * CreateTObject ()
 
static Toshi::TObject * CreateTObjectInPlace (void *a_pPtr)
 
static void InitialiseClass ()
 
static void DeinitialiseClass ()
 
static TFORCEINLINE TClassGetClassStatic ()
 

Protected Member Functions

TBOOL HandleKeyChange (TEmitter< TInputInterface, TInputInterface::InputEvent > &a_Emitter, TINT a_iKeyIndex, uint8_t a_ui8KeyState)
 
- Protected Member Functions inherited from TInputDeviceKeyboard
void UpdateVirtualButtons ()
 
- Protected Member Functions inherited from TInputDevice
TINT ProcessRepeats (EventEmitter &a_rEmitter, TFLOAT a_fDeltaTime)
 

Static Protected Member Functions

static TINT TranslateDXToDoodad (TINT doodad)
 
static TINT TranslateDoodadToDX (TINT dxkey)
 

Additional Inherited Members

- Public Types inherited from TInputDeviceKeyboard
enum  : Doodad {
  DOODAD_START = 0x20000 , VIRTKEY = 0x20001 , VIRTKEY_SHIFT = 0x20002 , VIRTKEY_CONTROL = 0x20003 ,
  VIRTKEY_ALT = 0x20004 , KEY_ESCAPE = 0x20005 , KEY_1 = 0x20006 , KEY_2 = 0x20007 ,
  KEY_3 = 0x20008 , KEY_4 = 0x20009 , KEY_5 = 0x2000A , KEY_6 = 0x2000B ,
  KEY_7 = 0x2000C , KEY_8 = 0x2000D , KEY_9 = 0x2000E , KEY_0 = 0x2000F ,
  KEY_MINUS = 0x20010 , KEY_EQUALS = 0x20011 , KEY_BACK = 0x20012 , KEY_TAB = 0x20013 ,
  KEY_Q = 0x20014 , KEY_W = 0x20015 , KEY_E = 0x20016 , KEY_R = 0x20017 ,
  KEY_T = 0x20018 , KEY_Y = 0x20019 , KEY_U = 0x2001A , KEY_I = 0x2001B ,
  KEY_O = 0x2001C , KEY_P = 0x2001D , KEY_LBRACKET = 0x2001E , KEY_RBRACKET = 0x2001F ,
  KEY_RETURN = 0x20020 , KEY_LCONTROL = 0x20021 , KEY_A = 0x20022 , KEY_S = 0x20023 ,
  KEY_D = 0x20024 , KEY_F = 0x20025 , KEY_G = 0x20026 , KEY_H = 0x20027 ,
  KEY_J = 0x20028 , KEY_K = 0x20029 , KEY_L = 0x2002A , KEY_SEMICOLON = 0x2002B ,
  KEY_APOSTROPHE = 0x2002C , KEY_GRAVE = 0x2002D , KEY_LSHIFT = 0x2002E , KEY_BACKSLASH = 0x2002F ,
  KEY_Z = 0x20030 , KEY_X = 0x20031 , KEY_C = 0x20032 , KEY_V = 0x20033 ,
  KEY_B = 0x20034 , KEY_N = 0x20035 , KEY_M = 0x20036 , KEY_COMMA = 0x20037 ,
  KEY_PERIOD = 0x20038 , KEY_SLASH = 0x20039 , KEY_RSHIFT = 0x2003A , KEY_MULTIPLY = 0x2003B ,
  KEY_LMENU = 0x2003c , KEY_SPACE = 0x2003d , KEY_CAPITAL = 0x2003e , KEY_F1 = 0x2003f ,
  KEY_F2 = 0x20040 , KEY_F3 = 0x20041 , KEY_F4 = 0x20042 , KEY_F5 = 0x20043 ,
  KEY_F6 = 0x20044 , KEY_F7 = 0x20045 , KEY_F8 = 0x20046 , KEY_F9 = 0x20047 ,
  KEY_F10 = 0x20048 , KEY_NUMLOCK = 0x20049 , KEY_SCROLL = 0x2004a , KEY_NUMPAD7 = 0x2004b ,
  KEY_NUMPAD8 = 0x2004c , KEY_NUMPAD9 = 0x2004d , KEY_SUBTRACT = 0x2004e , KEY_NUMPAD4 = 0x2004f ,
  KEY_NUMPAD5 = 0x20050 , KEY_NUMPAD6 = 0x20051 , KEY_ADD = 0x20052 , KEY_NUMPAD1 = 0x20053 ,
  KEY_NUMPAD2 = 0x20054 , KEY_NUMPAD3 = 0x20055 , KEY_NUMPAD0 = 0x20056 , KEY_DECIMAL = 0x20057 ,
  KEY_F11 = 0x20058 , KEY_F12 = 0x20059 , KEY_F13 = 0x2005a , KEY_F14 = 0x2005b ,
  KEY_F15 = 0x2005c , KEY_KANA = 0x2005d , KEY_CONVERT = 0x2005e , KEY_NOCONVERT = 0x2005f ,
  KEY_YEN = 0x20060 , KEY_NUMPADEQUALS = 0x20061 , KEY_CIRCUMFLEX = 0x20062 , KEY_AT = 0x20063 ,
  KEY_COLON = 0x20064 , KEY_UNDERLINE = 0x20065 , KEY_KANJI = 0x20066 , KEY_STOP = 0x20067 ,
  KEY_AX = 0x20068 , KEY_UNLABELED = 0x20069 , KEY_NUMPADENTER = 0x2006a , KEY_RCONTROL = 0x2006b ,
  KEY_NUMPADCOMMA = 0x2006c , KEY_DIVIDE = 0x2006d , KEY_SYSRQ = 0x2006e , KEY_RMENU = 0x2006f ,
  KEY_HOME = 0x20070 , KEY_PAUSE = 0x20071 , KEY_UP = 0x20072 , KEY_PRIOR = 0x20073 ,
  KEY_LEFT = 0x20074 , KEY_RIGHT = 0x20075 , KEY_END = 0x20076 , KEY_DOWN = 0x20077 ,
  KEY_NEXT = 0x20078 , KEY_INSERT = 0x20079 , KEY_DELETE = 0x2007a , KEY_LWIN = 0x2007b ,
  KEY_RWIN = 0x2007c , KEY_APPS = 0x2007d , KEY_POWER = 0x2007e , KEY_SLEEP = 0x2007f ,
  DOODAD_END = 0x20080
}
 
- Public Types inherited from TInputDevice
using EventEmitter = TInputInterface::EventEmitter
 
using Doodad = TINT
 
- Public Types inherited from TObject
enum  { IsTObject = TTRUE }
 
- Static Public Attributes inherited from TInputDeviceKeyboard
static constexpr TUINT KEYBOARD_NUM_DOODADS = 128
 
static constexpr TUINT VIRTSTK_DIRECTIONAL_MAPS = 2
 
- Static Public Attributes inherited from TInputDevice
static constexpr TINT INPUT_DEVICE_MOUSE_BUTTONS = 3
 
static constexpr TINT INPUT_DEVICE_MOUSE_WHEEL = 4
 
- Static Public Attributes inherited from TObject
static constexpr Toshi::TClass * PARENTCLASS = TNULL
 
static constinit Toshi::TClass ms_oClass = Toshi::TClass( "TObject", TObject::CreateTObject, TObject::CreateTObjectInPlace, TObject::InitialiseClass, TObject::DeinitialiseClass, 0, 2, sizeof( TObject ), alignof( TObject ) )
 
- Protected Attributes inherited from TInputDeviceKeyboard
TFLOAT m_aMags [4]
 
VirtStickDoodad m_aVirtStickDoodads [VIRTSTK_DIRECTIONAL_MAPS]
 
- Protected Attributes inherited from TInputDevice
TUINT m_uiDeviceIndex
 
TArray< RepeatInfom_Repeats
 
TArray< void * > m_Array2
 
TBOOL m_bUnknown
 
TBOOL m_bIsAcquired
 
TInputInterfacem_pInputInterface
 
- Protected Attributes inherited from TNodeList< T >::TNode
friend TNodeList
 
TNodeListm_pList
 
T * m_pNext
 
T * m_pPrev
 
- Static Protected Attributes inherited from TInputDevice
static constexpr TUINT MAX_DEVICE_COUNT = 14
 
static TInputDevices_aDevices [MAX_DEVICE_COUNT]
 
static TUINT s_uiDeviceCount
 

Detailed Description

Definition at line 9 of file TInputDeviceKeyboard_Win.h.

Constructor & Destructor Documentation

◆ TInputDXDeviceKeyboard()

TInputDXDeviceKeyboard::TInputDXDeviceKeyboard ( )

Definition at line 14 of file TInputDeviceKeyboard_Win.cpp.

15{
16 m_iSomeNum = 0;
17 m_pKeyStates1 = TNULL;
18 m_pKeyStates2 = TNULL;
19 m_poDXInputDevice = TNULL;
20 m_bFlag = TFALSE;
21 m_aKeys.InitialiseAll( { TNULL } );
22}
#define TNULL
Definition Typedefs.h:23
#define TFALSE
Definition Typedefs.h:24

Member Function Documentation

◆ Acquire()

TBOOL TInputDXDeviceKeyboard::Acquire ( )
overridevirtual

Implements TInputDevice.

Definition at line 33 of file TInputDeviceKeyboard_Win.cpp.

34{
35 m_bIsUpdating = TFALSE;
36 HRESULT hRes = m_poDXInputDevice->Acquire();
37
38 if ( SUCCEEDED( hRes ) )
39 {
41
42 if ( hRes != S_FALSE )
43 {
45 }
46 }
47 else
48 {
50 return TFALSE;
51 }
52
53 return TTRUE;
54}
#define TTRUE
Definition Typedefs.h:25
void SetAcquired(TBOOL a_bAcquired)

◆ BindToDIDevice()

const TBOOL TInputDXDeviceKeyboard::BindToDIDevice ( HWND a_hMainWindow,
LPCDIDEVICEINSTANCEA a_poDeviceInstance,
IDirectInputDevice8A * a_poDXInputDevice )

Definition at line 792 of file TInputDeviceKeyboard_Win.cpp.

793{
794 TASSERT( a_poDeviceInstance != NULL );
795 TASSERT( a_poDXInputDevice != NULL );
796
797 Initialise();
798 Release();
799
800 TUtil::MemCopy( &m_oDeviceInstance, a_poDeviceInstance, sizeof( DIDEVICEINSTANCEA ) );
801
802 m_poDXInputDevice = a_poDXInputDevice;
803 m_DIDevCaps.dwSize = sizeof( DIDEVCAPS );
804
805 m_poDXInputDevice->GetCapabilities( &m_DIDevCaps );
806 HRESULT hr = m_poDXInputDevice->SetDataFormat( &c_dfDIKeyboard );
807
808 if ( hr != DI_OK )
809 {
810 return TFALSE;
811 }
812
813 if ( a_hMainWindow )
814 {
815 if ( m_poDXInputDevice->SetCooperativeLevel( a_hMainWindow, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE ) != DI_OK )
816 {
817 return TFALSE;
818 }
819 }
820
821 m_bIsUpdating = TFALSE;
822 m_poDXInputDevice->EnumObjects( EnumObjectCallback, this, DIDFT_BUTTON );
823 return TTRUE;
824}
#define TASSERT(X,...)
Definition Defines.h:138
static BOOL CALLBACK EnumObjectCallback(LPCDIDEVICEOBJECTINSTANCEA a_poObjectInstance, LPVOID a_pvRef)
virtual void Release() override
static void * MemCopy(void *dst, const void *src, TSIZE size)
Definition TUtil.h:90

◆ Deinitialise()

TBOOL TInputDXDeviceKeyboard::Deinitialise ( )
virtual

Definition at line 222 of file TInputDeviceKeyboard_Win.cpp.

223{
224 Release();
225 return TTRUE;
226}

◆ EnumObjectCallback()

BOOL CALLBACK TInputDXDeviceKeyboard::EnumObjectCallback ( LPCDIDEVICEOBJECTINSTANCEA a_poObjectInstance,
LPVOID a_pvRef )
static

Definition at line 826 of file TInputDeviceKeyboard_Win.cpp.

827{
829 TINT iDoodad = TranslateDXToDoodad( a_poObjectInstance->dwOfs );
830
831 if ( iDoodad - 0x20000U < 0x80 )
832 {
833 iDoodad -= 0x20000U;
834
835 // Save name of key
836 auto iKeyNameLength = TStringManager::String8Length( a_poObjectInstance->tszName );
837 delete[] pKeyboard->m_aKeys[ iDoodad ].wszKeyName;
838 TWCHAR* wcsKeyName = new TWCHAR[ iKeyNameLength + 1 ];
839 TStringManager::StringCharToUnicode( wcsKeyName, a_poObjectInstance->tszName, -1 );
840 pKeyboard->m_aKeys[ iDoodad ].wszKeyName = wcsKeyName;
841
842 DIPROPSTRING oKeyName;
843 oKeyName.diph.dwSize = sizeof( DIPROPSTRING );
844 oKeyName.diph.dwHeaderSize = sizeof( DIPROPHEADER );
845 oKeyName.diph.dwHow = 1;
846 oKeyName.diph.dwObj = a_poObjectInstance->dwType >> 8 & 0xffff;
847
848 pKeyboard->m_poDXInputDevice->GetProperty( DIPROP_KEYNAME, &oKeyName.diph );
849
850 DIPROPDWORD oKeyScanCode;
851 oKeyScanCode.diph.dwSize = sizeof( oKeyScanCode );
852 oKeyScanCode.diph.dwHeaderSize = sizeof( DIPROPHEADER );
853 oKeyScanCode.diph.dwHow = 1;
854 oKeyScanCode.diph.dwObj = a_poObjectInstance->dwType >> 8 & 0xffff;
855
856 HRESULT hRes = pKeyboard->m_poDXInputDevice->GetProperty( DIPROP_SCANCODE, &oKeyScanCode.diph );
857
858 if ( hRes == S_OK )
859 pKeyboard->m_aKeys[ iDoodad ].dwKeyScanCode = oKeyScanCode.dwData;
860 else
861 pKeyboard->m_aKeys[ iDoodad ].dwKeyScanCode = -1;
862 }
863
864 return TRUE;
865}
#define TREINTERPRETCAST(TYPE, VALUE)
Definition Defines.h:68
wchar_t TWCHAR
Definition Typedefs.h:21
int TINT
Definition Typedefs.h:7
static TINT TranslateDXToDoodad(TINT doodad)
static TWCHAR * StringCharToUnicode(TWCHAR *a_UnicodeString, const TCHAR *a_CharString, TUINT32 a_iLength)
static TSIZE String8Length(const TCHAR *str)

◆ Flush()

TBOOL TInputDXDeviceKeyboard::Flush ( )
overridevirtual

Reimplemented from TInputDevice.

Definition at line 70 of file TInputDeviceKeyboard_Win.cpp.

71{
72 if ( IsAcquired() )
73 {
74 DWORD dwNumElements = -1;
75 HRESULT hRes = m_poDXInputDevice->GetDeviceData( sizeof( DIDEVICEOBJECTDATA ), NULL, &dwNumElements, 0 );
76
77 if ( SUCCEEDED( hRes ) )
78 {
80 return TTRUE;
81 }
82 else
83 {
84 m_bIsUpdating = TFALSE;
85 }
86 }
87
88 return TFALSE;
89}
TBOOL IsAcquired() const

◆ GetButtonCount()

TINT TInputDXDeviceKeyboard::GetButtonCount ( ) const
overridevirtual

Implements TInputDevice.

Definition at line 139 of file TInputDeviceKeyboard_Win.cpp.

140{
141 return 0;
142}

◆ HandleKeyChange()

TBOOL TInputDXDeviceKeyboard::HandleKeyChange ( TEmitter< TInputInterface, TInputInterface::InputEvent > & a_Emitter,
TINT a_iKeyIndex,
uint8_t a_ui8KeyState )
protected

Definition at line 249 of file TInputDeviceKeyboard_Win.cpp.

250{
251 TINT iDoodad = TranslateDXToDoodad( a_iKeyIndex );
252
253 if ( iDoodad == KEY_TAB )
254 {
255 if ( IsAltDown() )
256 {
257 return TFALSE;
258 }
259 }
260
261 if ( ( a_ui8KeyState & 0x80 ) == 0 )
262 {
263 // Key released
264 m_pKeyStates1[ a_iKeyIndex ] = 0;
265 m_pKeyStates2[ a_iKeyIndex ] = 0x80;
266
267 a_Emitter.Throw( TInputInterface::InputEvent( this, iDoodad, TInputInterface::EVENT_TYPE_GONE_UP ) );
268 }
269 else
270 {
271 // Key pressed
272 m_pKeyStates1[ a_iKeyIndex ] = 0x80;
273 m_pKeyStates2[ a_iKeyIndex ] = 0;
274
275 TWCHAR* wcsCharacter = TranslateDoodadToCharacter( iDoodad );
276 a_Emitter.Throw( TInputInterface::InputEvent( this, iDoodad, TInputInterface::EVENT_TYPE_GONE_DOWN, wcsCharacter ) );
277 }
278
279 return TTRUE;
280}
virtual TBOOL IsAltDown() const override
virtual TWCHAR * TranslateDoodadToCharacter(TINT doodad) const override
void Throw(Data *pData)
Definition TEvent.h:56

◆ Initialise()

TBOOL TInputDXDeviceKeyboard::Initialise ( )
virtual

Definition at line 211 of file TInputDeviceKeyboard_Win.cpp.

212{
213 m_iSomeNum = 0;
214
215 TUtil::MemClear( m_aBuffer, sizeof( m_aBuffer ) );
216 m_pKeyStates1 = m_aBuffer + m_iSomeNum * 256;
217 m_pKeyStates2 = m_aBuffer + m_iSomeNum * 256 + 256;
218
219 return TTRUE;
220}
static void MemClear(void *ptr, TSIZE size)
Definition TUtil.h:91

◆ IsAltDown()

TBOOL TInputDXDeviceKeyboard::IsAltDown ( ) const
overridevirtual

Implements TInputDeviceKeyboard.

Definition at line 174 of file TInputDeviceKeyboard_Win.cpp.

175{
176 return ( m_pKeyStates1[ DIK_LALT ] & 0x80 ) || ( m_pKeyStates1[ DIK_RALT ] & 0x80 );
177}

◆ IsControlDown()

TBOOL TInputDXDeviceKeyboard::IsControlDown ( ) const
overridevirtual

Implements TInputDeviceKeyboard.

Definition at line 169 of file TInputDeviceKeyboard_Win.cpp.

170{
171 return ( m_pKeyStates1[ DIK_LCONTROL ] & 0x80 ) || ( m_pKeyStates1[ DIK_RCONTROL ] & 0x80 );
172}

◆ IsDown()

TBOOL TInputDXDeviceKeyboard::IsDown ( TINT doodad) const
overridevirtual

Implements TInputDevice.

Definition at line 144 of file TInputDeviceKeyboard_Win.cpp.

145{
146 if ( !m_bIsUpdating )
147 return TFALSE;
148
149 if ( doodad == VIRTKEY_SHIFT )
150 return IsShiftDown();
151 else if ( doodad == VIRTKEY_CONTROL )
152 return IsControlDown();
153 else if ( doodad == VIRTKEY_ALT )
154 return IsAltDown();
155 else
156 return m_pKeyStates1[ TranslateDoodadToDX( doodad ) ] & 0x80;
157}
static TINT TranslateDoodadToDX(TINT dxkey)
virtual TBOOL IsShiftDown() const override
virtual TBOOL IsControlDown() const override

◆ IsEnabled()

TBOOL TInputDXDeviceKeyboard::IsEnabled ( ) const
overridevirtual

Implements TInputDevice.

Definition at line 159 of file TInputDeviceKeyboard_Win.cpp.

160{
161 return TTRUE;
162}

◆ IsShiftDown()

TBOOL TInputDXDeviceKeyboard::IsShiftDown ( ) const
overridevirtual

Implements TInputDeviceKeyboard.

Definition at line 164 of file TInputDeviceKeyboard_Win.cpp.

165{
166 return ( m_pKeyStates1[ DIK_LSHIFT ] & 0x80 ) || ( m_pKeyStates1[ DIK_RSHIFT ] & 0x80 );
167}

◆ ProcessEvents()

TINT TInputDXDeviceKeyboard::ProcessEvents ( TEmitter< TInputInterface, TInputInterface::InputEvent > & emitter,
float deltaTime )
overridevirtual

Implements TInputDevice.

Definition at line 91 of file TInputDeviceKeyboard_Win.cpp.

92{
93 if ( m_bIsUpdating )
94 {
95 if ( m_bFlag )
96 {
97 for ( TSIZE i = 0; i < 256; i++ )
98 {
99 if ( m_pKeyStates1[ i ] != m_pKeyStates2[ i ] )
100 {
101 HandleKeyChange( emitter, i, m_pKeyStates1[ i ] );
102 }
103 }
104
105 m_bFlag = TFALSE;
106 }
107
108 DWORD dwNumElements = 32;
109 DIDEVICEOBJECTDATA aDeviceData[ 32 ];
110 TUtil::MemClear( aDeviceData, sizeof( aDeviceData ) );
111 HRESULT hRes = m_poDXInputDevice->GetDeviceData( sizeof( DIDEVICEOBJECTDATA ), aDeviceData, &dwNumElements, 0 );
112
113 if ( SUCCEEDED( hRes ) )
114 {
115 TINT iNumProcessed = 0;
116 iNumProcessed += ProcessRepeats( emitter, deltaTime );
117 iNumProcessed += ProcessVirtualButtons( emitter, deltaTime );
118
119 for ( DWORD i = 0; i < dwNumElements; i++ )
120 {
121 HandleKeyChange( emitter, aDeviceData[ i ].dwOfs, TUINT8( aDeviceData[ i ].dwData ) );
122
123 if ( aDeviceData[ i ].dwData != 0 )
124 iNumProcessed++;
125 }
126
128 return iNumProcessed;
129 }
130
131 m_bIsUpdating = TFALSE;
132 Unacquire();
133 Acquire();
134 }
135
136 return 0;
137}
size_t TSIZE
Definition Typedefs.h:9
uint8_t TUINT8
Definition Typedefs.h:17
virtual TINT ProcessVirtualButtons(EventEmitter &a_rEmitter, TFLOAT flt)
TINT ProcessRepeats(EventEmitter &a_rEmitter, TFLOAT a_fDeltaTime)
TBOOL HandleKeyChange(TEmitter< TInputInterface, TInputInterface::InputEvent > &a_Emitter, TINT a_iKeyIndex, uint8_t a_ui8KeyState)
virtual TBOOL Acquire() override
virtual TBOOL Unacquire() override

◆ RefreshDirect()

void TInputDXDeviceKeyboard::RefreshDirect ( )
virtual

Definition at line 228 of file TInputDeviceKeyboard_Win.cpp.

229{
230 if ( !IsAcquired() )
231 return;
232
233 std::swap( m_pKeyStates1, m_pKeyStates2 );
234
235 if ( SUCCEEDED( m_poDXInputDevice->Poll() ) &&
236 m_poDXInputDevice->GetDeviceState( 256, m_pKeyStates1 ) == S_OK )
237 {
238 DWORD dwNumElements = 32;
239 m_poDXInputDevice->GetDeviceData( sizeof( DIDEVICEOBJECTDATA ), NULL, &dwNumElements, 0 );
240 m_bFlag = TTRUE;
241 m_bIsUpdating = TTRUE;
242 }
243 else
244 {
245 m_bIsUpdating = TFALSE;
246 }
247}

◆ Release()

void TInputDXDeviceKeyboard::Release ( )
overridevirtual

Implements TInputDevice.

Definition at line 24 of file TInputDeviceKeyboard_Win.cpp.

25{
26 if ( m_poDXInputDevice )
27 {
28 m_poDXInputDevice->Release();
29 m_poDXInputDevice = TNULL;
30 }
31}

◆ TDECLARE_CLASS()

TInputDXDeviceKeyboard::TDECLARE_CLASS ( TInputDXDeviceKeyboard ,
TInputDeviceKeyboard  )

◆ TranslateDoodadToCharacter()

TWCHAR * TInputDXDeviceKeyboard::TranslateDoodadToCharacter ( TINT doodad) const
overridevirtual

Implements TInputDeviceKeyboard.

Definition at line 194 of file TInputDeviceKeyboard_Win.cpp.

195{
196#pragma warning( disable : 4309 )
197 static TWCHAR s_Buffer[ 2 ];
198 static constexpr TCHAR s_TranslateArrayLowerCase[] = { 0x00, 0x00, 0x00, (TCHAR)0x80, (TCHAR)0xbf, 0x00, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x2d, 0x3d, 0x00, 0x00, 0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69, 0x6f, 0x70, 0x5b, 0x5d, 0x00, 0x00, 0x61, 0x73, 0x64, 0x66, 0x67, 0x68, 0x6a, 0x6b, 0x6c, 0x3b, 0x27, 0x60, 0x00, 0x5c, 0x7a, 0x78, 0x63, 0x76, 0x62, 0x6e, 0x6d, 0x2c, 0x2e, 0x2f, 0x00, 0x2a, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
199 static constexpr TCHAR s_TranslateArrayUpperCase[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5e, 0x26, 0x2a, 0x28, 0x29, 0x5f, 0x2b, 0x00, 0x00, 0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49, 0x4f, 0x50, 0x7b, 0x7d, 0x00, 0x00, 0x41, 0x53, 0x44, 0x46, 0x47, 0x48, 0x4a, 0x4b, 0x4c, 0x3b, 0x00, 0x7e, 0x00, 0x7c, 0x5a, 0x58, 0x43, 0x56, 0x42, 0x4e, 0x4d, 0x3c, 0x3e, 0x3f, 0x00, 0x2a, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
200#pragma warning( default : 4309 )
201
202 if ( !IsShiftDown() )
203 s_Buffer[ 0 ] = TWCHAR( s_TranslateArrayLowerCase[ doodad - 0x20000 ] );
204 else
205 s_Buffer[ 0 ] = TWCHAR( s_TranslateArrayUpperCase[ doodad - 0x20000 ] );
206
207 s_Buffer[ 1 ] = L'\0';
208 return s_Buffer;
209}
char TCHAR
Definition Typedefs.h:20

◆ TranslateDoodadToDX()

TINT TInputDXDeviceKeyboard::TranslateDoodadToDX ( TINT dxkey)
staticprotected

Definition at line 537 of file TInputDeviceKeyboard_Win.cpp.

538{
539 switch ( dxkey )
540 {
542 return DIK_ESCAPE;
544 return DIK_1;
546 return DIK_2;
548 return DIK_3;
550 return DIK_4;
552 return DIK_5;
554 return DIK_6;
556 return DIK_7;
558 return DIK_8;
560 return DIK_9;
562 return DIK_0;
564 return DIK_MINUS;
566 return DIK_EQUALS;
568 return DIK_BACK;
570 return DIK_TAB;
572 return DIK_Q;
574 return DIK_W;
576 return DIK_E;
578 return DIK_R;
580 return DIK_T;
582 return DIK_Y;
584 return DIK_U;
586 return DIK_I;
588 return DIK_O;
590 return DIK_P;
592 return DIK_LBRACKET;
594 return DIK_RBRACKET;
596 return DIK_RETURN;
598 return DIK_LCONTROL;
600 return DIK_A;
602 return DIK_S;
604 return DIK_D;
606 return DIK_F;
608 return DIK_G;
610 return DIK_H;
612 return DIK_J;
614 return DIK_K;
616 return DIK_L;
618 return DIK_SEMICOLON;
620 return DIK_APOSTROPHE;
622 return DIK_GRAVE;
624 return DIK_LSHIFT;
626 return DIK_BACKSLASH;
628 return DIK_Z;
630 return DIK_X;
632 return DIK_C;
634 return DIK_V;
636 return DIK_B;
638 return DIK_N;
640 return DIK_M;
642 return DIK_COMMA;
644 return DIK_PERIOD;
646 return DIK_SLASH;
648 return DIK_RSHIFT;
650 return DIK_MULTIPLY;
652 return DIK_LMENU;
654 return DIK_SPACE;
656 return DIK_CAPITAL;
658 return DIK_F1;
660 return DIK_F2;
662 return DIK_F3;
664 return DIK_F4;
666 return DIK_F5;
668 return DIK_F6;
670 return DIK_F7;
672 return DIK_F8;
674 return DIK_F9;
676 return DIK_F10;
678 return DIK_NUMLOCK;
680 return DIK_SCROLL;
682 return DIK_NUMPAD7;
684 return DIK_NUMPAD8;
686 return DIK_NUMPAD9;
688 return DIK_SUBTRACT;
690 return DIK_NUMPAD4;
692 return DIK_NUMPAD5;
694 return DIK_NUMPAD6;
696 return DIK_ADD;
698 return DIK_NUMPAD1;
700 return DIK_NUMPAD2;
702 return DIK_NUMPAD3;
704 return DIK_NUMPAD0;
706 return DIK_DECIMAL;
708 return DIK_F11;
710 return DIK_F12;
712 return DIK_F13;
714 return DIK_F14;
716 return DIK_F15;
718 return DIK_KANA;
720 return DIK_CONVERT;
722 return DIK_NOCONVERT;
724 return DIK_YEN;
726 return DIK_NUMPADEQUALS;
728 return DIK_CIRCUMFLEX;
730 return DIK_AT;
732 return DIK_COLON;
734 return DIK_UNDERLINE;
736 return DIK_KANJI;
738 return DIK_STOP;
740 return DIK_AX;
742 return DIK_UNLABELED;
744 return DIK_NUMPADENTER;
746 return DIK_RCONTROL;
748 return DIK_NUMPADCOMMA;
750 return DIK_DIVIDE;
752 return DIK_SYSRQ;
754 return DIK_RMENU;
756 return DIK_PAUSE;
758 return DIK_HOME;
760 return DIK_UP;
762 return DIK_PRIOR;
764 return DIK_LEFT;
766 return DIK_RIGHT;
768 return DIK_END;
770 return DIK_DOWN;
772 return DIK_NEXT;
774 return DIK_INSERT;
776 return DIK_DELETE;
778 return DIK_LWIN;
780 return DIK_RWIN;
782 return DIK_APPS;
784 return DIK_POWER;
786 return DIK_SLEEP;
787 default:
788 return 0;
789 }
790}

◆ TranslateDXToDoodad()

TINT TInputDXDeviceKeyboard::TranslateDXToDoodad ( TINT doodad)
staticprotected

Definition at line 282 of file TInputDeviceKeyboard_Win.cpp.

283{
284 switch ( doodad )
285 {
286 case DIK_ESCAPE:
288 case DIK_1:
290 case DIK_2:
292 case DIK_3:
294 case DIK_4:
296 case DIK_5:
298 case DIK_6:
300 case DIK_7:
302 case DIK_8:
304 case DIK_9:
306 case DIK_0:
308 case DIK_MINUS:
310 case DIK_EQUALS:
312 case DIK_BACK:
314 case DIK_TAB:
316 case DIK_Q:
318 case DIK_W:
320 case DIK_E:
322 case DIK_R:
324 case DIK_T:
326 case DIK_Y:
328 case DIK_U:
330 case DIK_I:
332 case DIK_O:
334 case DIK_P:
336 case DIK_LBRACKET:
338 case DIK_RBRACKET:
340 case DIK_RETURN:
342 case DIK_LCONTROL:
344 case DIK_A:
346 case DIK_S:
348 case DIK_D:
350 case DIK_F:
352 case DIK_G:
354 case DIK_H:
356 case DIK_J:
358 case DIK_K:
360 case DIK_L:
362 case DIK_SEMICOLON:
364 case DIK_APOSTROPHE:
366 case DIK_GRAVE:
368 case DIK_LSHIFT:
370 case DIK_BACKSLASH:
372 case DIK_Z:
374 case DIK_X:
376 case DIK_C:
378 case DIK_V:
380 case DIK_B:
382 case DIK_N:
384 case DIK_M:
386 case DIK_COMMA:
388 case DIK_PERIOD:
390 case DIK_SLASH:
392 case DIK_RSHIFT:
394 case DIK_MULTIPLY:
396 case DIK_LMENU:
398 case DIK_SPACE:
400 case DIK_CAPITAL:
402 case DIK_F1:
404 case DIK_F2:
406 case DIK_F3:
408 case DIK_F4:
410 case DIK_F5:
412 case DIK_F6:
414 case DIK_F7:
416 case DIK_F8:
418 case DIK_F9:
420 case DIK_F10:
422 case DIK_NUMLOCK:
424 case DIK_SCROLL:
426 case DIK_NUMPAD7:
428 case DIK_NUMPAD8:
430 case DIK_NUMPAD9:
432 case DIK_SUBTRACT:
434 case DIK_NUMPAD4:
436 case DIK_NUMPAD5:
438 case DIK_NUMPAD6:
440 case DIK_ADD:
442 case DIK_NUMPAD1:
444 case DIK_NUMPAD2:
446 case DIK_NUMPAD3:
448 case DIK_NUMPAD0:
450 case DIK_DECIMAL:
452 case DIK_F11:
454 case DIK_F12:
456 case DIK_F13:
458 case DIK_F14:
460 case DIK_F15:
462 case DIK_KANA:
464 case DIK_CONVERT:
466 case DIK_NOCONVERT:
468 case DIK_YEN:
470 case DIK_NUMPADEQUALS:
472 case DIK_CIRCUMFLEX:
474 case DIK_AT:
476 case DIK_COLON:
478 case DIK_UNDERLINE:
480 case DIK_KANJI:
482 case DIK_STOP:
484 case DIK_AX:
486 case DIK_UNLABELED:
488 case DIK_NUMPADENTER:
490 case DIK_RCONTROL:
492 case DIK_NUMPADCOMMA:
494 case DIK_DIVIDE:
496 case DIK_SYSRQ:
498 case DIK_RMENU:
500 case DIK_PAUSE:
502 case DIK_HOME:
504 case DIK_UP:
506 case DIK_PRIOR:
508 case DIK_LEFT:
510 case DIK_RIGHT:
512 case DIK_END:
514 case DIK_DOWN:
516 case DIK_NEXT:
518 case DIK_INSERT:
520 case DIK_DELETE:
522 case DIK_LWIN:
524 case DIK_RWIN:
526 case DIK_APPS:
528 case DIK_POWER:
530 case DIK_SLEEP:
532 default:
533 return 0;
534 }
535}

◆ Unacquire()

TBOOL TInputDXDeviceKeyboard::Unacquire ( )
overridevirtual

Implements TInputDevice.

Definition at line 56 of file TInputDeviceKeyboard_Win.cpp.

57{
58 m_bIsUpdating = TFALSE;
60
61 return SUCCEEDED( m_poDXInputDevice->Unacquire() );
62}

◆ Update()

void TInputDXDeviceKeyboard::Update ( float deltaTime)
overridevirtual

Implements TInputDevice.

Definition at line 64 of file TInputDeviceKeyboard_Win.cpp.

65{
66 if ( IsAcquired() )
67 m_bIsUpdating = TTRUE;
68}

◆ WasDown()

TBOOL TInputDXDeviceKeyboard::WasDown ( TINT doodad) const
overridevirtual

Implements TInputDeviceKeyboard.

Definition at line 179 of file TInputDeviceKeyboard_Win.cpp.

180{
181 if ( !m_bIsUpdating )
182 return TFALSE;
183
184 if ( doodad == VIRTKEY_SHIFT )
185 return ( m_pKeyStates2[ DIK_LSHIFT ] & 0x80 ) || ( m_pKeyStates2[ DIK_RSHIFT ] & 0x80 );
186 else if ( doodad == VIRTKEY_CONTROL )
187 return ( m_pKeyStates2[ DIK_LCONTROL ] & 0x80 ) || ( m_pKeyStates2[ DIK_RCONTROL ] & 0x80 );
188 else if ( doodad == VIRTKEY_ALT )
189 return ( m_pKeyStates2[ DIK_LALT ] & 0x80 ) || ( m_pKeyStates2[ DIK_RALT ] & 0x80 );
190 else
191 return m_pKeyStates2[ TranslateDXToDoodad( doodad ) ] & 0x80;
192}

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