Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller to Mouse SENS is broken. #147

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: futurITsic# Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Download
======

[![Github All Releases](https://img.shields.io/github/downloads/Tylemagne/Gopher360/total.svg?style=flat&label=Download%20Gopher360%20Standalone&logo=appveyor&colorA=00cc0a&colorB=000000)](https://github.com/Tylemagne/Gopher360/releases/download/v0.989/Gopher.exe)
[![Github All Releases](https://img.shields.io/github/downloads/Tylemagne/Gopher360/total.svg?style=flat&label=Download%20GopherRenewed%20Standalone&logo=appveyor&colorA=00cc0a&colorB=000000)](https://github.com/mike1084/GopherRenewed/releases/download/v0.991/GopherRenewed.exe)

Donate
======

[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ETDWNUEJG2UY2)
[![Become a patron](https://c5.patreon.com/external/logo/[email protected])](https://www.patreon.com/bePatron?u=1002457)

Compatible Controllers
======
Expand All @@ -25,7 +25,7 @@ Compatible Controllers
DualShock controllers are great, but you NEED to emulate Xinput for Gopher to see and understand them. Fortunately, Xinput emulation is a very popular thing, as there are just as many people with DualShock controllers as there are Xbox controllers. Listings coming soon.

### Third party
SOME third party controllers will most likely work as well. I haven't seen one not work, but I'd imagine some wouldn't. Research before buying, Gopher expects native Xinput devices, so the controller should as well. I won't be listing any for now until I know what ones will work. If I can find one that does the job and saves you from Microsoft's extreme profit margins, I'll list it.
SOME third party controllers will most likely work as well. I haven't seen one not work, but I'd imagine some wouldn't. Research before buying, **Gopher expects native Xinput devices,** so the controller should as well. I won't be listing any for now until I know what ones will work. If I can find one that does the job and saves you from Microsoft's extreme profit margins, I'll list it.

Feedback
======
Expand Down Expand Up @@ -62,7 +62,7 @@ Gopher separates itself from the competition by being efficient, small, portable

[![GitHub release](https://img.shields.io/github/release/Tylemagne/gopher360.svg)]()

[![Github commits (since latest release)](https://img.shields.io/github/commits-since/Tylemagne/gopher360/latest.svg)]()
[![Github commits (since latest release)](https://img.shields.io/github/commits-since/mike1084/GopherRenewed/latest.svg)]()

Requirements
======
Expand Down
22 changes: 19 additions & 3 deletions Windows/Gopher/ConfigFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ void ConfigFile::ExtractKeys()
std::ofstream outfile("config.ini");

// Begin config dump to file
outfile << "# GOPHER DEFAULT CONFIGURATION rev1.0 - Auto generated by Gopher360." << std::endl;
outfile << "# If you want a fresh one, just DELETE THIS FILE and re-run Gopher360." << std::endl;
outfile << "# GOPHER DEFAULT CONFIGURATION rev1.0 - Auto generated by GopherRenewed." << std::endl;
outfile << "# If you want a fresh one, just DELETE THIS FILE and re-run GopherRenewed." << std::endl;
outfile << "# Set which controller buttons will activate the configuration events." << std::endl;
outfile << "# SET 0 FOR NO FUNCTION." << std::endl;
outfile << "# AVAILABLE VALUES AT https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xinput_gamepad(v=vs.85).aspx" << std::endl;
Expand Down Expand Up @@ -135,13 +135,29 @@ void ConfigFile::ExtractKeys()
outfile << "GAMEPAD_TRIGGER_LEFT = 0" << std::endl;
outfile << "GAMEPAD_TRIGGER_RIGHT = 0" << std::endl;
outfile << "\n" << std::endl;
outfile << "# ADVANCED CONFIGURATION SETTINGS" << std::endl;
outfile << "# ADVANCED CONFIGURATION SETTINGS, REMOVE # ON SPECIFIC LINES TO ENABLE." << std::endl;
outfile << "\n" << std::endl;
outfile << "# ALLOWED CURSOR SPEEDS, FIRST WILL BE CHOSEN BY DEFAULT. VALUES > 1.0 WILL BE IGNORED. NO SPACES." << std::endl;
outfile << "CURSOR_SPEED = ULTRALOW=0.005,LOW=0.015,MED=0.025,HIGH=0.04" << std::endl;
outfile << "# CURSOR DEADZONE, DEFAULT = 6000" << std::endl;
outfile << "#DEAD_ZONE = 6000" << std::endl;
outfile << "\n" << std::endl;

outfile << "# PARAMETERS FOR SETTING SCROLLING SPEED AND DEADZONE." << std::endl;
outfile << "# SET SCROLLING SPEED." << std::endl;
outfile << "# SCROLL_SPEED = 0.1" << std::endl;
outfile << "# SET SCROLL DEADZONE, DEFAULT = 5000" << std::endl;
outfile << "# SCROLL_DEAD_ZONE = 5000" << std::endl;
outfile << "\n" << std::endl;

outfile << "# SET ACCELERATION FACTOR FOR NON-LINEAR CURSOR SPEED" << std::endl;
outfile << "# ACCELERATION_FACTOR = 3" << std::endl;
outfile << "\n" << std::endl;
outfile << "# Swaps the function of the thumbsticks. Set to 0 for default behavior or set to 1 to have the mouse movement on the right stick and scrolling on the left stick." << std::endl;
outfile << "SWAP_THUMBSTICKS = 0" << std::endl;
outfile << "\n" << std::endl;
outfile << "# HIGHLY EXPERIMENTAL FPS MODE, SET TO 1 TO ENABLE" << std::endl;
outfile << "FPS_MODE = 0" << std::endl;
// End config dump

outfile.close();
Expand Down
198 changes: 193 additions & 5 deletions Windows/Gopher/Gopher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,32 @@ void inputKeyboard(WORD cmd, DWORD flag)
SendInput(1, &input, sizeof(INPUT));
}

// Description:
// Send a keyboard input to the system based on the key value
// and its event type.
//
// Params:
// cmd The value of the key to send(see http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx)
// flag The KEYEVENT for the key
void inputKeyboardScan(WORD cmd, WORD flag)
{
INPUT input;
input.type = INPUT_KEYBOARD;
input.ki.wScan = cmd;
input.ki.time = 0;
input.ki.dwExtraInfo = 0;
input.ki.wVk = 0;
input.ki.dwFlags = flag;
SendInput(1, &input, sizeof(INPUT));
}

void inputKeyboardRaw(USHORT cmd, USHORT flag = 0)
{
RAWINPUT input;
input.data.keyboard.Flags = flag;
input.data.keyboard.VKey = cmd;
}

// Description:
// Send a keyboard input based on the key value with the "pressed down" event.
//
Expand Down Expand Up @@ -117,6 +143,10 @@ void Gopher::loadConfigFile()
//--------------------------------
// Advanced settings
//--------------------------------

// (EXPERIMENTAL) FPS mode toggle
FPS_MODE = strtol(cfg.getValueOfKey<std::string>("FPS_MODE").c_str(), 0, 0);


// Acceleration factor
acceleration_factor = strtof(cfg.getValueOfKey<std::string>("ACCELERATION_FACTOR").c_str(), 0);
Expand Down Expand Up @@ -167,6 +197,8 @@ void Gopher::loadConfigFile()
{
speeds.push_back(cur_speedf);
speed_names.push_back(cur_name);
// To make the vibration dependent on speed, multiply it to get in the same range.
speed_intensities.push_back(cur_speedf * 500000);
}
}

Expand All @@ -181,6 +213,10 @@ void Gopher::loadConfigFile()
speed_names.push_back("LOW");
speed_names.push_back("MED");
speed_names.push_back("HIGH");
speed_intensities.push_back(500);
speed_intensities.push_back(1000);
speed_intensities.push_back(1500);
speed_intensities.push_back(2000);
}
speed = speeds[0]; // Initialize the speed to the first speed stored. TODO: Set the speed to a saved speed that was last used when the application was closed last.

Expand Down Expand Up @@ -213,7 +249,14 @@ void Gopher::loop()

// Mouse functions
handleMouseMovement();
handleScrolling();
if (FPS_MODE)
{
handleStickMovement();
}
else
{
handleScrolling();
}

if (CONFIG_MOUSE_LEFT)
{
Expand Down Expand Up @@ -266,7 +309,7 @@ void Gopher::loop()
if (_xboxClickIsDown[CONFIG_SPEED_CHANGE])
{
const int CHANGE_SPEED_VIBRATION_INTENSITY = 65000; // Speed of the vibration motors when changing cursor speed.
const int CHANGE_SPEED_VIBRATION_DURATION = 450; // Duration of the cursor speed change vibration in milliseconds.
const int CHANGE_SPEED_VIBRATION_DURATION = 420; // Duration of the cursor speed change vibration in milliseconds.

speed_idx++;
if (speed_idx >= speeds.size())
Expand All @@ -275,7 +318,7 @@ void Gopher::loop()
}
speed = speeds[speed_idx];
printf("Setting speed to %f (%s)...\n", speed, speed_names[speed_idx].c_str());
pulseVibrate(CHANGE_SPEED_VIBRATION_DURATION, CHANGE_SPEED_VIBRATION_INTENSITY, CHANGE_SPEED_VIBRATION_INTENSITY);
pulseVibrate(CHANGE_SPEED_VIBRATION_DURATION, speed_intensities[speed_idx], speed_intensities[speed_idx]);
}

// Update all controller keys.
Expand Down Expand Up @@ -502,7 +545,7 @@ void Gopher::handleMouseMovement()
short tx;
short ty;

if (SWAP_THUMBSTICKS == 0)
if ((SWAP_THUMBSTICKS == 0 && FPS_MODE == 0) || (SWAP_THUMBSTICKS == 1 && FPS_MODE == 1))
{
// Use left stick
tx = _currentState.Gamepad.sThumbLX;
Expand Down Expand Up @@ -537,7 +580,82 @@ void Gopher::handleMouseMovement()
y -= dy;
_yRest = y - (float)((int)y);

SetCursorPos((int)x, (int)y); //after all click input processing
INPUT input;
input.type = INPUT_MOUSE;
input.mi.dx = dx;
input.mi.dy = dy * -1;
input.mi.dwFlags = MOUSEEVENTF_MOVE;
input.mi.time = 0;
SendInput(1, &input, sizeof(INPUT));
}


void Gopher::handleKeyboardPress(int keyToPress) {
DWORD keyFlag = KEYEVENTF_UNICODE;

// If there previously has been a key press, check it!
if (key_pressed) {
if (key_pressed != keyToPress) {
printf("We got a mismatch!");
inputKeyboardUp(key_pressed);

//inputKeyboardScan(keyToPress, keyFlag);
inputKeyboardDown(keyToPress);
}
else {
//inputKeyboardScan(keyToPress, keyFlag);

}
}
// Otherwise, we can just send the key.
else {
inputKeyboardDown(keyToPress);
//inputKeyboardScan(keyToPress, keyFlag);
}
printf("%d", key_pressed);
key_pressed = keyToPress;
}


void Gopher::handleStickMovement() {

short tx = _currentState.Gamepad.sThumbLX;
short ty = _currentState.Gamepad.sThumbLY;
//int aKey = 0x1E, wKey = 0x11, dKey = 0x20, sKey = 0x1F;
int aKey = 37, wKey = 38, dKey = 39, sKey = 40;
//int dKey = 68, aKey = 65, wKey = 87, sKey = 83;
float lengthsq = tx * tx + ty * ty;
if (lengthsq > DEAD_ZONE * DEAD_ZONE) {

// If the x-distance is greater than the y-distance...
if (tx * tx > ty * ty) {
// d-key (right movement!)
if (tx > 0) {
handleKeyboardPress(dKey);
}
else {
handleKeyboardPress(aKey);
}
}

else {
// w-key (up movement!)
if (ty > 0) {
handleKeyboardPress(wKey);
}
// s-key (down movement!)
else {
handleKeyboardPress(sKey);
}
}
}

else {
inputKeyboardUp(key_pressed);
key_pressed = NULL;
}


}

// Description:
Expand Down Expand Up @@ -611,6 +729,68 @@ void Gopher::handleTriggers(WORD lKey, WORD rKey)
}
}


// This function only takes the left and right mouse as input.
// It handles the triggers so as to click the mouse buttons accordingly.
void Gopher::handleTriggersMouse(WORD lKey, WORD rKey)
{
bool lTriggerIsDown = _currentState.Gamepad.bLeftTrigger > TRIGGER_DEAD_ZONE;
bool rTriggerIsDown = _currentState.Gamepad.bRightTrigger > TRIGGER_DEAD_ZONE;
DWORD lKeyDown = NULL, lKeyUp = NULL, rKeyDown = NULL, rKeyUp = NULL;
if (lKey == 0x01) {
if (rKey == 0x02) {
lKeyDown = MOUSEEVENTF_LEFTDOWN;
lKeyUp = MOUSEEVENTF_LEFTUP;
rKeyDown = MOUSEEVENTF_RIGHTDOWN;
rKeyUp = MOUSEEVENTF_RIGHTUP;
}
else {
return;
}
}
else if (lKey == 0x02) {
if (rKey == 0x01) {
lKeyDown = MOUSEEVENTF_RIGHTDOWN;
lKeyUp = MOUSEEVENTF_RIGHTUP;
rKeyDown = MOUSEEVENTF_LEFTDOWN;
rKeyUp = MOUSEEVENTF_LEFTUP;
}
else {
return;
}
}
else {
return;
}


if (lTriggerIsDown != _lTriggerPrevious)
{
_lTriggerPrevious = lTriggerIsDown;
if (lTriggerIsDown)
{
mouseEvent(lKeyDown);
}
else
{
mouseEvent(lKeyUp);
}
}

if (rTriggerIsDown != _rTriggerPrevious)
{
_rTriggerPrevious = rTriggerIsDown;
if (rTriggerIsDown)
{
mouseEvent(rKeyDown);
}
else
{
mouseEvent(rKeyUp);
}
}
}

// Description:
// Handles the state of a controller button press.
//
Expand Down Expand Up @@ -818,3 +998,11 @@ bool Gopher::erasePressedKey(WORD key)

return false;
}



void Gopher::toggleFPSMode()
{
FPS_MODE = !FPS_MODE;
printf("FPS Mode: %d\n", FPS_MODE);
}
Loading