Skip to content

Commit

Permalink
Improvement: button names instead of codes
Browse files Browse the repository at this point in the history
  • Loading branch information
r57zone committed Oct 31, 2022
1 parent 0606519 commit 64bd6d5
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 14 deletions.
6 changes: 2 additions & 4 deletions README.RU.md
Expand Up @@ -45,13 +45,13 @@ Razer Hydra | Левый Vive контроллер | Правый Vive конт
------------ | -------------
Включение, выключение приседания | `ALT` + `9` и `ALT` + `0` (заменяет на нажатие тачпада)

- Для HMD можно использовать любой драйвер, с поддержкой приседания по кнопке. Например, можно использовать [OpenVR-ArduinoHMD драйвер](https://github.com/r57zone/OpenVR-ArduinoHMD) или [TrueOpenVR и SteamVR мост драйвер](https://github.com/TrueOpenVR) для HMD (FreeTrack для HMD из смартфонов или ArduinoHMD для [полноценных DIY шлемов](https://github.com/TrueOpenVR/TrueOpenVR-DIY/blob/master/HMD/HMD.RU.md)).
- Для HMD можно использовать любой драйвер, с поддержкой приседания по кнопке. Например, можно использовать [OpenVR-ArduinoHMD драйвер](https://github.com/r57zone/OpenVR-ArduinoHMD) или [TrueOpenVR и SteamVR мост драйвер](https://github.com/TrueOpenVR) для HMD (FreeTrack для HMD из смартфонов или ArduinoHMD для [полноценных DIY шлемов](https://github.com/TrueOpenVR/TrueOpenVR-DIY/blob/master/HMD/HMD.RU.md)). По умолчанию это кнопка `PAUSE`, изменить её можно в конфигурационном файле "default.vrsettings", параметр `CrouchPressKey`, название нужной кнопки можно найти [здесь](https://github.com/r57zone/DualShock4-emulator/blob/master/BINDINGS.RU.md).

- Изменить тип контроллеров, с Valve Index на HTC Vive, можно изменив значение `true` на `false`, параметра `IndexControllers`, в конфигурационном файле "default.vrsettings", параметр `CustomPressKey`

- Во время нажатия кнопки 3, на правом контроллере Razer Hydra, также нажимается кнопка клавиатуры (кнопка настраивается). Настройки приседания можно найти в конфигурационном файле "default.vrsettings".

- Поддерживается нажатие кнопки клавиатуры, на кнопку 4, левого контроллера. По умолчанию это кнопка `V`, изменить её можно в конфигурационном файле "default.vrsettings", параметр `CustomPressKey`, код нужной кнопки можно найти [здесь](https://github.com/r57zone/Half-Life-Alyx-novr/blob/master/BINDINGS.md#codes). Включить её можно в конфигурационном файле, изменив значение `false` на `true`, параметра `EnableCustomKey` и она заменит нажатие тачпада контроллера.
- Поддерживается нажатие кнопки клавиатуры, на кнопку 4, левого контроллера. По умолчанию это кнопка `V`, изменить её можно в конфигурационном файле "default.vrsettings", параметр `CustomPressKey`, название нужной кнопки можно найти [здесь](https://github.com/r57zone/DualShock4-emulator/blob/master/BINDINGS.RU.md). Включить её можно в конфигурационном файле, изменив значение `false` на `true`, параметра `EnableCustomKey` и она заменит нажатие тачпада контроллера.

- Отредактировать раскладку контроллеров можно также в "SteamVR Bindings UI", открыв настройки SteamVR, выбрав "Advance Settings" -> "Show" и перейдя в пункт контроллеры.

Expand All @@ -61,8 +61,6 @@ Razer Hydra | Левый Vive контроллер | Правый Vive конт
3. [Добавьте параметр](https://youtu.be/QCA3m4_3IJM?t=197) `"activateMultipleDrivers" : true,` в конфиг "...\Steam\config\steamvr.vrsettings", в раздел `steamvr`.
4. Измените мёртвую зону, если ваш стик уходит в сторону, в конфиге "..\Steam\steamapps\common\SteamVR\drivers\razer_hydra\hydra\resources\settings\default.vrsettings", параметр `JoyStickDeadZone`. Чтобы определить значение мёртвой зоны, для проблемного стика, можно использовать [эту программу](https://github.com/r57zone/Sixence-Razer-Hydra-sample/releases).

Дополнительная информация есть в [вики](https://github.com/betavr/steamvr_driver_hydra/wiki).

## Решение проблем
**• Стик наклонен в одну из сторон и не двигается в протиположную**<br>
Закройте SteamVR, отключите USB провод контроллеров, подождите 5-10 секунд и подключите снова.
Expand Down
6 changes: 2 additions & 4 deletions README.md
Expand Up @@ -45,13 +45,13 @@ Description | Razer Hydra Button
------------ | -------------
Turning on, off crouch | `ALT` + `9` and `ALT` + `0` (replaced to touchpad press)

- For HMD, you can use any driver that supports crouch by button. For example, you can use [OpenVR-ArduinoHMD Driver](https://github.com/r57zone/OpenVR-ArduinoHMD) or [TrueOpenVR and SteamVR Bridge Driver](https://github.com/TrueOpenVR) for HMD (FreeTrack for HMD from smartphones or ArduinoHMD for [full-fledged DIY headsets](https://github.com/TrueOpenVR/TrueOpenVR-DIY/blob/master/HMD/HMD.RU.md)).
- For HMD, you can use any driver that supports crouch by button. For example, you can use [OpenVR-ArduinoHMD Driver](https://github.com/r57zone/OpenVR-ArduinoHMD) or [TrueOpenVR and SteamVR Bridge Driver](https://github.com/TrueOpenVR) for HMD (FreeTrack for HMD from smartphones or ArduinoHMD for [full-fledged DIY headsets](https://github.com/TrueOpenVR/TrueOpenVR-DIY/blob/master/HMD/HMD.md)). By default, this is the `PAUSE` button, you can change it in the "default.vrsettings" configuration file, the `CrouchPressKey` parameter, the name of the desired button can be found [here](https://github.com/r57zone/DualShock4-emulator/blob/master/BINDINGS.md).

- You can change the type of controllers from Valve Index to HTC Vive by changing the value `true` to `false`, parameter `IndexControllers`, in the configuration file "default.vrsettings", parameter `CustomPressKey`

- While pressing button 3, on the right Razer Hydra controller, the keyboard button is also pressed (the button is configurable). Crouch settings can be found in the configuration file "default.vrsettings".

- Supports pressing the keyboard button, on button 4, of the left controller. By default, this is the `V` button, you can change it in the "default.vrsettings" configuration file, the `CustomPressKey` parameter, the code for the desired button can be found [here](https://github.com/r57zone/Half-Life-Alyx-novr/blob/master/BINDINGS.md#codes). You can turn it on in the configuration file by changing the value of `false` to `true`, the `EnableCustomKey` parameter and it will replace pressing the controller touchpad.
- Supports pressing the keyboard button, on button 4, of the left controller. By default, this is the `V` button, you can change it in the "default.vrsettings" configuration file, the `CustomPressKey` parameter, the name for the desired button can be found [here](https://github.com/r57zone/DualShock4-emulator/blob/master/BINDINGS.md). You can turn it on in the configuration file by changing the value of `false` to `true`, the `EnableCustomKey` parameter and it will replace pressing the controller touchpad.

- You can also edit the controller layout in the "SteamVR Bindings UI" by opening the SteamVR settings, selecting "Advance Settings" -> "Show" and going to the controllers item.

Expand All @@ -62,8 +62,6 @@ Turning on, off crouch | `ALT` + `9` and `ALT` + `0` (replaced to touchpad press
3. [Add option](https://youtu.be/QCA3m4_3IJM?t=197) `"activateMultipleDrivers" : true,` to config "...\Steam\config\steamvr.vrsettings", to `steamvr` section.
4. Change the dead zone if your stick goes to the side in config "..\Steam\steamapps\common\SteamVR\drivers\razer_hydra\hydra\resources\settings\default.vrsettings", option `JoyStickDeadZone`. To determine the value of the dead zone can use [this program](https://github.com/r57zone/Sixence-Razer-Hydra-sample/releases).

For more detailed instructions please visit the [wiki](https://github.com/betavr/steamvr_driver_hydra/wiki).

## Problems solving
**• The stick is tilted to one side and does not move to the opposite side**<br>
Close SteamVR, unplug the controllers USB cable, wait 5-10 seconds and plug it back in.
Expand Down
130 changes: 126 additions & 4 deletions drivers/driver_hydra/driver_hydra.cpp
Expand Up @@ -65,8 +65,8 @@ static const char * const k_pch_Hydra_Section = "hydra";
//static const char * const k_pch_Hydra_RenderModel_String = "rendermodel";
static const char * const k_pch_Hydra_EnableIMU_Bool = "EnableImu";
static const char * const k_pch_Hydra_JoystickDeadzone_Float = "JoyStickDeadZone";
static const char * const k_pch_Hydra_CrouchPressKey_Int32 = "CrouchPressKey";
static const char * const k_pch_Hydra_CustomPressKey_Int32 = "CustomPressKey";
static const char * const k_pch_Hydra_CrouchPressKey_String = "CrouchPressKey";
static const char * const k_pch_Hydra_CustomPressKey_String = "CustomPressKey";
static const char * const k_pch_Hydra_CrouchOffset_Float = "CrouchOffset";
static const char * const k_pch_Hydra_RecognizeAsIndexControllers_Bool = "IndexControllers";
static const char * const k_pch_Hydra_EnableCustomKey_Bool = "EnableCustomKey";
Expand All @@ -77,6 +77,126 @@ static void GenerateSerialNumber(char *p, int psize, int base, int controller)
_snprintf(p, psize, "hydra%d_controller%d", base, controller);
}

int KeyNameToKeyCode(std::string KeyName) {
std::transform(KeyName.begin(), KeyName.end(), KeyName.begin(), ::toupper);

if (KeyName == "NONE") return 0;

else if (KeyName == "MOUSE-LEFT-BTN") return VK_LBUTTON;
else if (KeyName == "MOUSE-RIGHT-BTN") return VK_RBUTTON;
else if (KeyName == "MOUSE-MIDDLE-BTN") return VK_MBUTTON;
else if (KeyName == "MOUSE-SIDE1-BTN") return VK_XBUTTON1;
else if (KeyName == "MOUSE-SIDE2-BTN") return VK_XBUTTON2;

else if (KeyName == "ESCAPE") return VK_ESCAPE;
else if (KeyName == "F1") return VK_F1;
else if (KeyName == "F2") return VK_F2;
else if (KeyName == "F3") return VK_F3;
else if (KeyName == "F4") return VK_F4;
else if (KeyName == "F5") return VK_F5;
else if (KeyName == "F6") return VK_F6;
else if (KeyName == "F7") return VK_F7;
else if (KeyName == "F8") return VK_F8;
else if (KeyName == "F9") return VK_F9;
else if (KeyName == "F10") return VK_F10;
else if (KeyName == "F11") return VK_F11;
else if (KeyName == "F12") return VK_F12;

else if (KeyName == "~") return 192;
else if (KeyName == "1") return '1';
else if (KeyName == "2") return '2';
else if (KeyName == "3") return '3';
else if (KeyName == "4") return '4';
else if (KeyName == "5") return '5';
else if (KeyName == "6") return '6';
else if (KeyName == "7") return '7';
else if (KeyName == "8") return '8';
else if (KeyName == "9") return '9';
else if (KeyName == "0") return '0';
else if (KeyName == "-") return 189;
else if (KeyName == "=") return 187;

else if (KeyName == "TAB") return VK_TAB;
else if (KeyName == "CAPS-LOCK") return VK_CAPITAL;
else if (KeyName == "SHIFT") return VK_SHIFT;
else if (KeyName == "CTRL") return VK_CONTROL;
else if (KeyName == "WIN") return VK_LWIN;
else if (KeyName == "ALT") return VK_MENU;
else if (KeyName == "SPACE") return VK_SPACE;
else if (KeyName == "ENTER") return VK_RETURN;
else if (KeyName == "BACKSPACE") return VK_BACK;

else if (KeyName == "Q") return 'Q';
else if (KeyName == "W") return 'W';
else if (KeyName == "E") return 'E';
else if (KeyName == "R") return 'R';
else if (KeyName == "T") return 'T';
else if (KeyName == "Y") return 'Y';
else if (KeyName == "U") return 'U';
else if (KeyName == "I") return 'I';
else if (KeyName == "O") return 'O';
else if (KeyName == "P") return 'P';
else if (KeyName == "[") return '[';
else if (KeyName == "]") return ']';
else if (KeyName == "A") return 'A';
else if (KeyName == "S") return 'S';
else if (KeyName == "D") return 'D';
else if (KeyName == "F") return 'F';
else if (KeyName == "G") return 'G';
else if (KeyName == "H") return 'H';
else if (KeyName == "J") return 'J';
else if (KeyName == "K") return 'K';
else if (KeyName == "L") return 'L';
else if (KeyName == ";") return 186;
else if (KeyName == "'") return 222;
else if (KeyName == "\\") return 220;
else if (KeyName == "Z") return 'Z';
else if (KeyName == "X") return 'X';
else if (KeyName == "C") return 'C';
else if (KeyName == "V") return 'V';
else if (KeyName == "B") return 'B';
else if (KeyName == "N") return 'N';
else if (KeyName == "M") return 'M';
else if (KeyName == "<") return 188;
else if (KeyName == ">") return 190;
else if (KeyName == "?") return 191;

else if (KeyName == "PRINTSCREEN") return VK_SNAPSHOT;
else if (KeyName == "SCROLL-LOCK") return VK_SCROLL;
else if (KeyName == "PAUSE") return VK_PAUSE;
else if (KeyName == "INSERT") return VK_INSERT;
else if (KeyName == "HOME") return VK_HOME;
else if (KeyName == "PAGE-UP") return VK_NEXT;
else if (KeyName == "DELETE") return VK_DELETE;
else if (KeyName == "END") return VK_END;
else if (KeyName == "PAGE-DOWN") return VK_PRIOR;

else if (KeyName == "UP") return VK_UP;
else if (KeyName == "DOWN") return VK_DOWN;
else if (KeyName == "LEFT") return VK_LEFT;
else if (KeyName == "RIGHT") return VK_RIGHT;

else if (KeyName == "NUM-LOCK") return VK_NUMLOCK;
else if (KeyName == "NUMPAD0") return VK_NUMPAD0;
else if (KeyName == "NUMPAD1") return VK_NUMPAD1;
else if (KeyName == "NUMPAD2") return VK_NUMPAD2;
else if (KeyName == "NUMPAD3") return VK_NUMPAD3;
else if (KeyName == "NUMPAD4") return VK_NUMPAD4;
else if (KeyName == "NUMPAD5") return VK_NUMPAD5;
else if (KeyName == "NUMPAD6") return VK_NUMPAD6;
else if (KeyName == "NUMPAD7") return VK_NUMPAD7;
else if (KeyName == "NUMPAD8") return VK_NUMPAD8;
else if (KeyName == "NUMPAD9") return VK_NUMPAD9;

else if (KeyName == "NUMPAD-DIVIDE") return VK_DIVIDE;
else if (KeyName == "NUMPAD-MULTIPLY") return VK_MULTIPLY;
else if (KeyName == "NUMPAD-MINUS") return VK_SUBTRACT;
else if (KeyName == "NUMPAD-PLUS") return VK_ADD;
else if (KeyName == "NUMPAD-DEL") return VK_DECIMAL;

else return 0;
}

//-----------------------------------------------------------------------------
// Purpose: Watchdog
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -372,13 +492,15 @@ class CHydraControllerDriver : public vr::ITrackedDeviceServerDriver
m_bEnableHoldThumbpad = true;

// Crouch key code (for send to another HMD drivers)
m_nCrouchPressKey = vr::VRSettings()->GetInt32(k_pch_Hydra_Section, k_pch_Hydra_CrouchPressKey_Int32);
vr::VRSettings()->GetString(k_pch_Hydra_Section, k_pch_Hydra_CrouchPressKey_String, buf, sizeof(buf));
m_nCrouchPressKey = KeyNameToKeyCode(buf);

// Crouch offset Z
m_fCrouchOffset = vr::VRSettings()->GetFloat(k_pch_Hydra_Section, k_pch_Hydra_CrouchOffset_Float);

// Cutom key code (for send to another apps)
m_nCustomPressKey = vr::VRSettings()->GetInt32(k_pch_Hydra_Section, k_pch_Hydra_CustomPressKey_Int32);
vr::VRSettings()->GetString(k_pch_Hydra_Section, k_pch_Hydra_CustomPressKey_String, buf, sizeof(buf));
m_nCustomPressKey = KeyNameToKeyCode(buf);

// Enable custom key on left Index controller
EnabledCustomKey = vr::VRSettings()->GetBool(k_pch_Hydra_Section, k_pch_Hydra_EnableCustomKey_Bool);
Expand Down
4 changes: 2 additions & 2 deletions resources/settings/default.vrsettings
Expand Up @@ -2,10 +2,10 @@
"hydra" : {
"IndexControllers" : true,
"JoyStickDeadZone" : 0.0,
"CrouchPressKey": 19,
"CrouchPressKey": "PAUSE",
"CrouchOffset": 0.7,
"EnableCustomKey" : false,
"CustomPressKey": 86,
"CustomPressKey": "V",
"EnableImu" : true
}
}

0 comments on commit 64bd6d5

Please sign in to comment.