|
8 | 8 | #include <vector> |
9 | 9 | #include <thread> |
10 | 10 | #include <chrono> |
| 11 | +#include <algorithm> |
11 | 12 |
|
12 | 13 | #if defined( _WINDOWS ) |
13 | 14 | #include <windows.h> |
@@ -83,8 +84,8 @@ static const char * const k_pch_arduinoHMD_DebugMode_Bool = "DebugMode"; |
83 | 84 | static const char * const k_pch_arduinoHMD_Section = "arduinohmd"; |
84 | 85 | static const char * const k_pch_arduinoHMD_ArduinoRequire_Bool = "ArduinoRequire"; |
85 | 86 | static const char * const k_pch_arduinoHMD_COM_port_Int32 = "COMPort"; |
86 | | -static const char * const k_pch_arduinoHMD_CenteringKey_Int32 = "CenteringKey"; |
87 | | -static const char * const k_pch_arduinoHMD_CrouchPressKey_Int32 = "CrouchPressKey"; |
| 87 | +static const char * const k_pch_arduinoHMD_CenteringKey_String = "CenteringKey"; |
| 88 | +static const char * const k_pch_arduinoHMD_CrouchPressKey_String = "CrouchPressKey"; |
88 | 89 | static const char * const k_pch_arduinoHMD_CrouchOffset_Float = "CrouchOffset"; |
89 | 90 |
|
90 | 91 | HANDLE hSerial; |
@@ -211,6 +212,126 @@ void ArduinoIMUStart() { |
211 | 212 | } |
212 | 213 | } |
213 | 214 |
|
| 215 | +int KeyNameToKeyCode(std::string KeyName) { |
| 216 | + std::transform(KeyName.begin(), KeyName.end(), KeyName.begin(), ::toupper); |
| 217 | + |
| 218 | + if (KeyName == "NONE") return 0; |
| 219 | + |
| 220 | + else if (KeyName == "MOUSE-LEFT-BTN") return VK_LBUTTON; |
| 221 | + else if (KeyName == "MOUSE-RIGHT-BTN") return VK_RBUTTON; |
| 222 | + else if (KeyName == "MOUSE-MIDDLE-BTN") return VK_MBUTTON; |
| 223 | + else if (KeyName == "MOUSE-SIDE1-BTN") return VK_XBUTTON1; |
| 224 | + else if (KeyName == "MOUSE-SIDE2-BTN") return VK_XBUTTON2; |
| 225 | + |
| 226 | + else if (KeyName == "ESCAPE") return VK_ESCAPE; |
| 227 | + else if (KeyName == "F1") return VK_F1; |
| 228 | + else if (KeyName == "F2") return VK_F2; |
| 229 | + else if (KeyName == "F3") return VK_F3; |
| 230 | + else if (KeyName == "F4") return VK_F4; |
| 231 | + else if (KeyName == "F5") return VK_F5; |
| 232 | + else if (KeyName == "F6") return VK_F6; |
| 233 | + else if (KeyName == "F7") return VK_F7; |
| 234 | + else if (KeyName == "F8") return VK_F8; |
| 235 | + else if (KeyName == "F9") return VK_F9; |
| 236 | + else if (KeyName == "F10") return VK_F10; |
| 237 | + else if (KeyName == "F11") return VK_F11; |
| 238 | + else if (KeyName == "F12") return VK_F12; |
| 239 | + |
| 240 | + else if (KeyName == "~") return 192; |
| 241 | + else if (KeyName == "1") return '1'; |
| 242 | + else if (KeyName == "2") return '2'; |
| 243 | + else if (KeyName == "3") return '3'; |
| 244 | + else if (KeyName == "4") return '4'; |
| 245 | + else if (KeyName == "5") return '5'; |
| 246 | + else if (KeyName == "6") return '6'; |
| 247 | + else if (KeyName == "7") return '7'; |
| 248 | + else if (KeyName == "8") return '8'; |
| 249 | + else if (KeyName == "9") return '9'; |
| 250 | + else if (KeyName == "0") return '0'; |
| 251 | + else if (KeyName == "-") return 189; |
| 252 | + else if (KeyName == "=") return 187; |
| 253 | + |
| 254 | + else if (KeyName == "TAB") return VK_TAB; |
| 255 | + else if (KeyName == "CAPS-LOCK") return VK_CAPITAL; |
| 256 | + else if (KeyName == "SHIFT") return VK_SHIFT; |
| 257 | + else if (KeyName == "CTRL") return VK_CONTROL; |
| 258 | + else if (KeyName == "WIN") return VK_LWIN; |
| 259 | + else if (KeyName == "ALT") return VK_MENU; |
| 260 | + else if (KeyName == "SPACE") return VK_SPACE; |
| 261 | + else if (KeyName == "ENTER") return VK_RETURN; |
| 262 | + else if (KeyName == "BACKSPACE") return VK_BACK; |
| 263 | + |
| 264 | + else if (KeyName == "Q") return 'Q'; |
| 265 | + else if (KeyName == "W") return 'W'; |
| 266 | + else if (KeyName == "E") return 'E'; |
| 267 | + else if (KeyName == "R") return 'R'; |
| 268 | + else if (KeyName == "T") return 'T'; |
| 269 | + else if (KeyName == "Y") return 'Y'; |
| 270 | + else if (KeyName == "U") return 'U'; |
| 271 | + else if (KeyName == "I") return 'I'; |
| 272 | + else if (KeyName == "O") return 'O'; |
| 273 | + else if (KeyName == "P") return 'P'; |
| 274 | + else if (KeyName == "[") return '['; |
| 275 | + else if (KeyName == "]") return ']'; |
| 276 | + else if (KeyName == "A") return 'A'; |
| 277 | + else if (KeyName == "S") return 'S'; |
| 278 | + else if (KeyName == "D") return 'D'; |
| 279 | + else if (KeyName == "F") return 'F'; |
| 280 | + else if (KeyName == "G") return 'G'; |
| 281 | + else if (KeyName == "H") return 'H'; |
| 282 | + else if (KeyName == "J") return 'J'; |
| 283 | + else if (KeyName == "K") return 'K'; |
| 284 | + else if (KeyName == "L") return 'L'; |
| 285 | + else if (KeyName == ";") return 186; |
| 286 | + else if (KeyName == "'") return 222; |
| 287 | + else if (KeyName == "\\") return 220; |
| 288 | + else if (KeyName == "Z") return 'Z'; |
| 289 | + else if (KeyName == "X") return 'X'; |
| 290 | + else if (KeyName == "C") return 'C'; |
| 291 | + else if (KeyName == "V") return 'V'; |
| 292 | + else if (KeyName == "B") return 'B'; |
| 293 | + else if (KeyName == "N") return 'N'; |
| 294 | + else if (KeyName == "M") return 'M'; |
| 295 | + else if (KeyName == "<") return 188; |
| 296 | + else if (KeyName == ">") return 190; |
| 297 | + else if (KeyName == "?") return 191; |
| 298 | + |
| 299 | + else if (KeyName == "PRINTSCREEN") return VK_SNAPSHOT; |
| 300 | + else if (KeyName == "SCROLL-LOCK") return VK_SCROLL; |
| 301 | + else if (KeyName == "PAUSE") return VK_PAUSE; |
| 302 | + else if (KeyName == "INSERT") return VK_INSERT; |
| 303 | + else if (KeyName == "HOME") return VK_HOME; |
| 304 | + else if (KeyName == "PAGE-UP") return VK_NEXT; |
| 305 | + else if (KeyName == "DELETE") return VK_DELETE; |
| 306 | + else if (KeyName == "END") return VK_END; |
| 307 | + else if (KeyName == "PAGE-DOWN") return VK_PRIOR; |
| 308 | + |
| 309 | + else if (KeyName == "UP") return VK_UP; |
| 310 | + else if (KeyName == "DOWN") return VK_DOWN; |
| 311 | + else if (KeyName == "LEFT") return VK_LEFT; |
| 312 | + else if (KeyName == "RIGHT") return VK_RIGHT; |
| 313 | + |
| 314 | + else if (KeyName == "NUM-LOCK") return VK_NUMLOCK; |
| 315 | + else if (KeyName == "NUMPAD0") return VK_NUMPAD0; |
| 316 | + else if (KeyName == "NUMPAD1") return VK_NUMPAD1; |
| 317 | + else if (KeyName == "NUMPAD2") return VK_NUMPAD2; |
| 318 | + else if (KeyName == "NUMPAD3") return VK_NUMPAD3; |
| 319 | + else if (KeyName == "NUMPAD4") return VK_NUMPAD4; |
| 320 | + else if (KeyName == "NUMPAD5") return VK_NUMPAD5; |
| 321 | + else if (KeyName == "NUMPAD6") return VK_NUMPAD6; |
| 322 | + else if (KeyName == "NUMPAD7") return VK_NUMPAD7; |
| 323 | + else if (KeyName == "NUMPAD8") return VK_NUMPAD8; |
| 324 | + else if (KeyName == "NUMPAD9") return VK_NUMPAD9; |
| 325 | + |
| 326 | + else if (KeyName == "NUMPAD-DIVIDE") return VK_DIVIDE; |
| 327 | + else if (KeyName == "NUMPAD-MULTIPLY") return VK_MULTIPLY; |
| 328 | + else if (KeyName == "NUMPAD-MINUS") return VK_SUBTRACT; |
| 329 | + else if (KeyName == "NUMPAD-PLUS") return VK_ADD; |
| 330 | + else if (KeyName == "NUMPAD-DEL") return VK_DECIMAL; |
| 331 | + |
| 332 | + else return 0; |
| 333 | +} |
| 334 | + |
214 | 335 | //----------------------------------------------------------------------------- |
215 | 336 | // Purpose: |
216 | 337 | //----------------------------------------------------------------------------- |
@@ -251,9 +372,13 @@ class CDeviceDriver : public vr::ITrackedDeviceServerDriver, public vr::IVRDispl |
251 | 372 | m_bStereoMode = vr::VRSettings()->GetBool(k_pch_steamvr_Section, k_pch_arduinoHMD_Stereo_Bool); |
252 | 373 | m_bDebugMode = vr::VRSettings()->GetBool(k_pch_steamvr_Section, k_pch_arduinoHMD_DebugMode_Bool); |
253 | 374 |
|
254 | | - m_centeringKey = vr::VRSettings()->GetInt32(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_CenteringKey_Int32); |
| 375 | + vr::VRSettings()->GetString(k_pch_steamvr_Section, k_pch_arduinoHMD_CenteringKey_String, buf, sizeof(buf)); |
| 376 | + m_centeringKey = KeyNameToKeyCode(buf); |
| 377 | + |
| 378 | + vr::VRSettings()->GetString(k_pch_steamvr_Section, k_pch_arduinoHMD_CrouchPressKey_String, buf, sizeof(buf)); |
| 379 | + m_crouchPressKey = KeyNameToKeyCode(buf); |
| 380 | + |
255 | 381 | m_crouchOffset = vr::VRSettings()->GetFloat(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_CrouchOffset_Float); |
256 | | - m_crouchPressKey = vr::VRSettings()->GetInt32(k_pch_arduinoHMD_Section, k_pch_arduinoHMD_CrouchPressKey_Int32); |
257 | 382 |
|
258 | 383 | //DriverLog( "driver_arduinohmd: Serial Number: %s\n", m_sSerialNumber.c_str() ); |
259 | 384 | //DriverLog( "driver_arduinohmd: Model Number: %s\n", m_sModelNumber.c_str() ); |
|
0 commit comments