Platform_Win32_Input_KeyboardDevice.cpp
Go to the documentation of this file.00001 //*** Platform_Win32_Input_KeyboardDevice.cpp *** 00002 00003 #include "Platform_Win32_Input_KeyboardDevice.h" 00004 #include "Platform_OS.h" 00005 00006 #define WIN32_LEAN_AND_MEAN 00007 #define VC_EXTRALEAN 00008 #include <windows.h> 00009 00010 //*** Constructor *** 00011 00012 Platform_Win32_Input_KeyboardDevice::Platform_Win32_Input_KeyboardDevice(): 00013 characterBufferCount_(0) 00014 { 00015 for (int i=0; i<256; i++) 00016 { 00017 charStates_[i]=false; 00018 charKeycodes_[i]=0; 00019 } 00020 } 00021 00022 00023 //*** Destructor *** 00024 00025 Platform_Win32_Input_KeyboardDevice::~Platform_Win32_Input_KeyboardDevice() 00026 { 00027 } 00028 00029 00030 //*** IsKeyDown *** 00031 00032 bool Platform_Win32_Input_KeyboardDevice::IsKeyDown(KeyCode keyCode) const 00033 { 00034 if ((Platform::GetPlatform_OS() && Platform::GetPlatform_OS()->HasFocus()) && GetAsyncKeyState(keyCode)!=0) 00035 { 00036 return true; 00037 } 00038 00039 return false; 00040 } 00041 00042 00043 //*** IsCharDown *** 00044 00045 bool Platform_Win32_Input_KeyboardDevice::IsCharDown(char ascii) const 00046 { 00047 return charStates_[(unsigned char)ascii]; 00048 } 00049 00050 00051 //*** SetCharPressed *** 00052 00053 void Platform_Win32_Input_KeyboardDevice::SetCharPressed(char ascii, unsigned char keycode) 00054 { 00055 charStates_[(unsigned char)ascii]=true; 00056 charKeycodes_[(unsigned char)ascii]=keycode; 00057 AddBufferedCharacter(ascii); 00058 } 00059 00060 00061 //*** SetCharReleased *** 00062 00063 void Platform_Win32_Input_KeyboardDevice::SetCharReleased(unsigned char keycode) 00064 { 00065 for (int i=0; i<256; i++) 00066 { 00067 if (charKeycodes_[i]==keycode) 00068 { 00069 charStates_[i]=false; 00070 return; 00071 } 00072 } 00073 } 00074 00075 00076 //*** AddBufferedCharacter *** 00077 00078 void Platform_Win32_Input_KeyboardDevice::AddBufferedCharacter(char ascii) 00079 { 00080 while (characterBufferCount_>=256) 00081 { 00082 for (int i=1; i<characterBufferCount_; i++) 00083 { 00084 characterBuffer_[i-1]=characterBuffer_[i]; 00085 } 00086 characterBufferCount_--; 00087 } 00088 00089 characterBuffer_[characterBufferCount_]=ascii; 00090 characterBufferCount_++; 00091 } 00092 00093 00094 //*** ClearBufferedCharacters *** 00095 00096 void Platform_Win32_Input_KeyboardDevice::ClearBufferedCharacters() const 00097 { 00098 characterBufferCount_=0; 00099 } 00100 00101 00102 //*** GetBufferedCharacterCount *** 00103 00104 int Platform_Win32_Input_KeyboardDevice::GetBufferedCharacterCount() const 00105 { 00106 return characterBufferCount_; 00107 } 00108 00109 00110 //*** GetBufferedCharacter *** 00111 00112 char Platform_Win32_Input_KeyboardDevice::GetBufferedCharacter(int index) const 00113 { 00114 if (index<0 || index>=characterBufferCount_) 00115 { 00116 return 0; 00117 } 00118 00119 return characterBuffer_[index]; 00120 }
Reproduction/republishing of any material on this site without permission is strictly prohibited.
