Skip to content
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
4 changes: 4 additions & 0 deletions Windows/Gopher/ConfigFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ void ConfigFile::ExtractKeys()
outfile << "# ACCELERATION_FACTOR = 3" << 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 << "DEAD_ZONE = 6000 # Thumbstick dead zone to use for mouse movement. Absolute maximum thumbstick value is 32768." << std::endl;
outfile << "SCROLL_DEAD_ZONE = 5000 # Thumbstick dead zone to use for scroll wheel movement. Absolute maximum thumbstick value is 32768." << std::endl;
outfile << "TRIGGER_DEAD_ZONE = 0 # Dead zone for the left and right triggers to detect a trigger press. Range from 0 (accept all input) to 255 (ignore all input)." << std::endl;
outfile << "SCROLL_SPEED = 0.1 # Speed at which you scroll (scalar)" << std::endl;
// End config dump

outfile.close();
Expand Down
39 changes: 23 additions & 16 deletions Windows/Gopher/Gopher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,16 +473,18 @@ float Gopher::getDelta(short t)
// Calculates a multiplier for an analog thumbstick based on the update rate.
//
// Params:
// tValue The thumbstick value
// magnitude The thumbstick magnitude in XY-plane, which is sqrt(deltaX*deltaX + deltaY*deltaY). Must be larger than deadzone.
// deadzone The dead zone to use for this thumbstick
// accel An exponent to use to create an input curve (Optional). 0 to use a linear input
//
// Returns:
// Multiplier used to properly scale the given thumbstick value.
float Gopher::getMult(float lengthsq, float deadzone, float accel = 0.0f)
float Gopher::getMult(float magnitude, float deadzone, float accel = 0.0f)
{
// Normalize the thumbstick value.
float mult = (sqrt(lengthsq) - deadzone) / (MAXSHORT - deadzone);
// Normalize the thumbstick value (result is in range 0 to 1).
// Note that the smallest accepted thumbstick distance is deadzone.
// Thus, 0% would be deadzone (and below) and 100% would be (MAXSHORT - deadzone)
float mult = (magnitude - deadzone) / (MAXSHORT - deadzone);

// Apply a curve to the normalized thumbstick value.
if (accel > 0.0001f)
Expand All @@ -505,14 +507,14 @@ void Gopher::handleMouseMovement()
if (SWAP_THUMBSTICKS == 0)
{
// Use left stick
tx = _currentState.Gamepad.sThumbLX;
ty = _currentState.Gamepad.sThumbLY;
tx = getDelta(_currentState.Gamepad.sThumbLX);
ty = getDelta(_currentState.Gamepad.sThumbLY);
}
else
{
// Use right stick
tx = _currentState.Gamepad.sThumbRX;
ty = _currentState.Gamepad.sThumbRY;
tx = getDelta(_currentState.Gamepad.sThumbRX);
ty = getDelta(_currentState.Gamepad.sThumbRY);
}

float x = cursor.x + _xRest;
Expand All @@ -525,10 +527,10 @@ void Gopher::handleMouseMovement()
float lengthsq = tx * tx + ty * ty;
if (lengthsq > DEAD_ZONE * DEAD_ZONE)
{
float mult = speed * getMult(lengthsq, DEAD_ZONE, acceleration_factor);
float mult = speed * getMult(sqrt(lengthsq), DEAD_ZONE, acceleration_factor);

dx = getDelta(tx) * mult;
dy = getDelta(ty) * mult;
dx = tx * mult;
dy = ty * mult;
}

x += dx;
Expand Down Expand Up @@ -561,12 +563,17 @@ void Gopher::handleScrolling()
}

// Handle dead zone
float magnitude = sqrt(tx * tx + ty * ty);

if (magnitude > SCROLL_DEAD_ZONE)
float magnitudeX = abs(tx);
float magnitudeY = abs(ty);
if (magnitudeX > SCROLL_DEAD_ZONE)
{
int scrollX = tx * getMult(magnitudeX, SCROLL_DEAD_ZONE) * SCROLL_SPEED;
mouseEvent(MOUSEEVENTF_HWHEEL, scrollX);
}
if (magnitudeY > SCROLL_DEAD_ZONE)
{
mouseEvent(MOUSEEVENTF_HWHEEL, tx * getMult(tx * tx, SCROLL_DEAD_ZONE) * SCROLL_SPEED);
mouseEvent(MOUSEEVENTF_WHEEL, ty * getMult(ty * ty, SCROLL_DEAD_ZONE) * SCROLL_SPEED);
int scrollY = ty * getMult(magnitudeY, SCROLL_DEAD_ZONE) * SCROLL_SPEED;
mouseEvent(MOUSEEVENTF_WHEEL, scrollY);
}
}

Expand Down
4 changes: 3 additions & 1 deletion Windows/Gopher/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ BOOL isRunningAsAdministrator(); // Check if administrator, makes on-screen keyb

int main()
{
char* buildDate = "2021-01-20";

CXBOXController controller(1);
Gopher gopher(&controller);
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTitle( TEXT( "Gopher360" ) );

system("Color 1D");

printf("Welcome to Gopher360 - a VERY fast and lightweight controller-to-keyboard & mouse input tool.\n");
printf("Welcome to Gopher360 (built %s) - a VERY fast and lightweight controller-to-keyboard & mouse input tool.\n", buildDate);
printf("All you need is an Xbox360/Xbone controller (wired or wireless adapter), or DualShock (with InputMapper 1.5+)\n");
printf("Gopher will autofind the xinput device and begin reading input - if nothing happens, verify connectivity.\n");
printf("See the GitHub repository at bit.ly/1syAhMT for more info. Twitter contact: TylerAt60FPS\n\n-------------------------\n\n");
Expand Down