Skip to content

Commit

Permalink
better trackpad click management
Browse files Browse the repository at this point in the history
  • Loading branch information
mmorselli committed Jun 13, 2018
1 parent a23ac5d commit 1241bc6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
34 changes: 30 additions & 4 deletions Joy2OpenVR/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ namespace
// trackpad modifier, click if pressed, touch otherwise
bool p_trackpad1_click = false;
bool p_trackpad2_click = false;
bool trackpad1_click_reverse;
bool trackpad2_click_reverse;

DWORD exitCode = 0;
CString lastcmd;
Expand Down Expand Up @@ -384,18 +386,33 @@ namespace
//************************************************
void Axis_Set(CString id, CString xvalue, CString yvalue)
{
// touch event at x,y
executeCommandLine("client_commandline.exe buttonevent touchandhold " + id + " 32", exitCode);
executeCommandLine("client_commandline.exe axisevent " + id + " 0 "+ xvalue+" "+yvalue, exitCode);

if ((p_trackpad1_click && id == steamvr_controller1_id) || (p_trackpad2_click && id == steamvr_controller2_id))
// emulate trackpad click
if (id == steamvr_controller1_id && (!p_trackpad1_click == trackpad1_click_reverse))
{
executeCommandLine("client_commandline.exe buttonevent pressandhold " + id + " 32", exitCode); // touchpad pressed
touchpadpressed = true;
return;
}
else {


if (id == steamvr_controller2_id && (!p_trackpad2_click == trackpad2_click_reverse))
{
executeCommandLine("client_commandline.exe buttonevent pressandhold " + id + " 32", exitCode); // touchpad pressed
touchpadpressed = true;
return;
}

// if pressed, but no click request, unpress
if (touchpadpressed)
{
executeCommandLine("client_commandline.exe buttonevent unpress " + id + " 32", exitCode); // touchpad unpressed
touchpadpressed = false;
}

}


Expand Down Expand Up @@ -658,7 +675,10 @@ namespace
}



// string to bool
bool ToBool(const std::string & s) {
return s == "true";
}

}

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


trackpad1_click_reverse = ToBool(ini.GetValue("axes", "trackpad1_click_reverse", "false"));
trackpad2_click_reverse = ToBool(ini.GetValue("axes", "trackpad2_click_reverse", "false"));





// Create the window of the application
sf::String appname="Joy2OpenVR ";
appname += "0.4b";
appname += "0.5b";
sf::RenderWindow window(sf::VideoMode(600, 780), appname, sf::Style::Close);
window.setVerticalSyncEnabled(true);

Expand Down
14 changes: 8 additions & 6 deletions Joy2OpenVR/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ grip2 = 3

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

0 comments on commit 1241bc6

Please sign in to comment.