Skip to content

Commit 1241bc6

Browse files
committed
better trackpad click management
1 parent a23ac5d commit 1241bc6

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

Joy2OpenVR/Main.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ namespace
6565
// trackpad modifier, click if pressed, touch otherwise
6666
bool p_trackpad1_click = false;
6767
bool p_trackpad2_click = false;
68+
bool trackpad1_click_reverse;
69+
bool trackpad2_click_reverse;
6870

6971
DWORD exitCode = 0;
7072
CString lastcmd;
@@ -384,18 +386,33 @@ namespace
384386
//************************************************
385387
void Axis_Set(CString id, CString xvalue, CString yvalue)
386388
{
389+
// touch event at x,y
387390
executeCommandLine("client_commandline.exe buttonevent touchandhold " + id + " 32", exitCode);
388391
executeCommandLine("client_commandline.exe axisevent " + id + " 0 "+ xvalue+" "+yvalue, exitCode);
389392

390-
if ((p_trackpad1_click && id == steamvr_controller1_id) || (p_trackpad2_click && id == steamvr_controller2_id))
393+
// emulate trackpad click
394+
if (id == steamvr_controller1_id && (!p_trackpad1_click == trackpad1_click_reverse))
391395
{
392396
executeCommandLine("client_commandline.exe buttonevent pressandhold " + id + " 32", exitCode); // touchpad pressed
393397
touchpadpressed = true;
398+
return;
394399
}
395-
else {
400+
401+
402+
if (id == steamvr_controller2_id && (!p_trackpad2_click == trackpad2_click_reverse))
403+
{
404+
executeCommandLine("client_commandline.exe buttonevent pressandhold " + id + " 32", exitCode); // touchpad pressed
405+
touchpadpressed = true;
406+
return;
407+
}
408+
409+
// if pressed, but no click request, unpress
410+
if (touchpadpressed)
411+
{
396412
executeCommandLine("client_commandline.exe buttonevent unpress " + id + " 32", exitCode); // touchpad unpressed
397413
touchpadpressed = false;
398414
}
415+
399416
}
400417

401418

@@ -658,7 +675,10 @@ namespace
658675
}
659676

660677

661-
678+
// string to bool
679+
bool ToBool(const std::string & s) {
680+
return s == "true";
681+
}
662682

663683
}
664684

@@ -710,10 +730,16 @@ int main(int argc,char *argv[])
710730
sf::String profile = (sf::String)ini.GetValue("main", "profile", "0");
711731

712732

733+
trackpad1_click_reverse = ToBool(ini.GetValue("axes", "trackpad1_click_reverse", "false"));
734+
trackpad2_click_reverse = ToBool(ini.GetValue("axes", "trackpad2_click_reverse", "false"));
735+
736+
737+
738+
713739

714740
// Create the window of the application
715741
sf::String appname="Joy2OpenVR ";
716-
appname += "0.4b";
742+
appname += "0.5b";
717743
sf::RenderWindow window(sf::VideoMode(600, 780), appname, sf::Style::Close);
718744
window.setVerticalSyncEnabled(true);
719745

Joy2OpenVR/config.ini

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ grip2 = 3
1919

2020
[axes]
2121
; joystick axes to trackpad. possible values: trackpad1,trackpad2,trigger1,trigger2 (trackpad1 or trigger1 binds to steamvr_controller1_id)
22-
xy_axes = trigger1
23-
zr_axes = trigger2
24-
uv_axes = trigger1
22+
xy_axes = trackpad1
23+
zr_axes = trackpad1
24+
uv_axes = trackpad2
2525
; trackpad click at given coordinates when pressed, any buttons ID allowed, typically bind to thumbstick click
26-
; setting it to always makes the trackpad always clicked
27-
trackpad1_click = 11
28-
trackpad2_click = 10
26+
trackpad1_click = 8
27+
trackpad2_click = 9
28+
; if true, trackpad is clicked when the above buttons are NOT clicked, touched otherwise
29+
trackpad1_click_reverse = false
30+
trackpad2_click_reverse = false

0 commit comments

Comments
 (0)