Mustafa
Mustafa
CC#
Created by Mustafa on 4/30/2024 in #help
[✅] Receiving Game Controller Input while Minimized (WinForms C#) | Repost
Pretty general question here. How would I go about receiving input from my user while they aren't tabbed into the program or have a different window as their foreground window? I'm using the InputSimulator Nuget package (InputSimulatorStandard version), and I'd like for my program to send inputs to a game window when it receives controller input. My only issue, now, is that the controller input isn't received unless I have my application as the foreground window.
private async void T_Tick(object sender, EventArgs e)
{
Gamepad gamepad = null;

if (RawGameController.RawGameControllers.Count > 0)
{
RawGameController rawGameController = RawGameController.RawGameControllers[0];
gamepad = Gamepad.FromGameController(rawGameController);
}

if (gamepad != null)
{
var reading = gamepad.GetCurrentReading();

switch (reading.Buttons)
{
case GamepadButtons.DPadUp:
MessageBox.Show("input received");
break;
case GamepadButtons.DPadDown:
break;
}
}
else
{
MessageBox.Show("gamepad is equal to null");
}
}
private async void T_Tick(object sender, EventArgs e)
{
Gamepad gamepad = null;

if (RawGameController.RawGameControllers.Count > 0)
{
RawGameController rawGameController = RawGameController.RawGameControllers[0];
gamepad = Gamepad.FromGameController(rawGameController);
}

if (gamepad != null)
{
var reading = gamepad.GetCurrentReading();

switch (reading.Buttons)
{
case GamepadButtons.DPadUp:
MessageBox.Show("input received");
break;
case GamepadButtons.DPadDown:
break;
}
}
else
{
MessageBox.Show("gamepad is equal to null");
}
}
private async void controllerZooming_CheckedChanged(object sender, EventArgs e)
{
SaveSettings();
GetSettings();
if (controllerZooming.Checked)
{
t.Tick += T_Tick;
t.Interval = 100;
t.Start();
}
else
{
if (t.Enabled) t.Stop();
await Log("Stopped");
}
}
private async void controllerZooming_CheckedChanged(object sender, EventArgs e)
{
SaveSettings();
GetSettings();
if (controllerZooming.Checked)
{
t.Tick += T_Tick;
t.Interval = 100;
t.Start();
}
else
{
if (t.Enabled) t.Stop();
await Log("Stopped");
}
}
This timer runs when a checkbox is on, and is stopped when that checkbox is turned off. It functions fine, but I can't receive said controller input unless the app is opened, which kind of ruins the whole point of this functionality. I've experimented with trying to use something of similar function to GetAsyncKeyState(), but as far as I know, nothing of such would work for a controller. Previously, I created a thread regarding this question and received two answers; one to use RawGameController rather than Windows.Gaming.Input.Gamepad, and the other to check if my application receives input in the background. While the use of RawGameController did work for the project, my program did not receive background input while minimized. Upon using Spy++ as another user recommended, I reaffirmed that my program could not receive input when minimized. I've tried to run my inputs via a background thread, but to no avail, as controller input was still only received while my program was the foreground window. Would appreciate some help on what direction I should try going with this.
32 replies
CC#
Created by Mustafa on 4/28/2024 in #help
Receiving Game Controller Input while Minimized (WinForms C#)
Pretty general question here. How would I go about receiving input from my user while they aren't tabbed into the program or have a different window as their foreground window? I'm using the InputSimulator Nuget package (InputSimulatorStandard version), and I'd like for my program to send inputs to a game window when it receives controller input. My only issue, now, is that the controller input isn't received unless I have my application as the foreground window.
private async void T_Tick(object sender, EventArgs e)
{
if (Gamepad.Gamepads.Count > 0)
{
Controller = Gamepad.Gamepads.First();
var Reading = Controller.GetCurrentReading();
switch (Reading.Buttons) {
case GamepadButtons.DPadUp:
Process[] process = Process.GetProcessesByName("RobloxPlayerBeta");

Process robloxProcess = process.FirstOrDefault();
if (robloxProcess != null)
{
IntPtr h = robloxProcess.MainWindowHandle;
SetForegroundWindow(h);
await Log("We're tabbed in");
InputSimulator inputSim = new InputSimulator();
inputSim.Mouse.VerticalScroll(3);
}
break;
// add other buttons here
}
return;
}
}
private async void T_Tick(object sender, EventArgs e)
{
if (Gamepad.Gamepads.Count > 0)
{
Controller = Gamepad.Gamepads.First();
var Reading = Controller.GetCurrentReading();
switch (Reading.Buttons) {
case GamepadButtons.DPadUp:
Process[] process = Process.GetProcessesByName("RobloxPlayerBeta");

Process robloxProcess = process.FirstOrDefault();
if (robloxProcess != null)
{
IntPtr h = robloxProcess.MainWindowHandle;
SetForegroundWindow(h);
await Log("We're tabbed in");
InputSimulator inputSim = new InputSimulator();
inputSim.Mouse.VerticalScroll(3);
}
break;
// add other buttons here
}
return;
}
}
This timer runs when a checkbox is on, and is stopped when that checkbox is turned off. It functions fine, but I can't receive said controller input unless the app is opened, which kind of ruins the whole point of this functionality. I've experimented with the use of GetAsyncKeyState(), but as far as I know, that wouldn't work for a controller.
41 replies
CC#
Created by Mustafa on 4/27/2024 in #help
✅ Receiving Input While Minimized (WinForms C#)
Pretty general question here. How would I go about receiving input from my user while they aren't tabbed into the program or have a different window as their foreground window? I'm using the InputSimulator Nuget package (InputSimulatorStandard version), and I'd like for my program to send inputs to a game window when it receives controller input. My only issue, now, is that the controller input isn't received unless I have my application as the foreground window.
private async void T_Tick(object sender, EventArgs e)
{
if (Gamepad.Gamepads.Count > 0)
{
Controller = Gamepad.Gamepads.First();
var Reading = Controller.GetCurrentReading();
switch (Reading.Buttons) {
case GamepadButtons.DPadUp:
Process[] process = Process.GetProcessesByName("RobloxPlayerBeta");

Process robloxProcess = process.FirstOrDefault();
if (robloxProcess != null)
{
IntPtr h = robloxProcess.MainWindowHandle;
SetForegroundWindow(h);
await Log("We're tabbed in");
InputSimulator inputSim = new InputSimulator();
inputSim.Mouse.VerticalScroll(3);
}
break;
// add other buttons here
}
return;
}
}
private async void T_Tick(object sender, EventArgs e)
{
if (Gamepad.Gamepads.Count > 0)
{
Controller = Gamepad.Gamepads.First();
var Reading = Controller.GetCurrentReading();
switch (Reading.Buttons) {
case GamepadButtons.DPadUp:
Process[] process = Process.GetProcessesByName("RobloxPlayerBeta");

Process robloxProcess = process.FirstOrDefault();
if (robloxProcess != null)
{
IntPtr h = robloxProcess.MainWindowHandle;
SetForegroundWindow(h);
await Log("We're tabbed in");
InputSimulator inputSim = new InputSimulator();
inputSim.Mouse.VerticalScroll(3);
}
break;
// add other buttons here
}
return;
}
}
This timer runs when a checkbox is on, and is stopped when that checkbox is turned off. It functions fine, but I can't receive said controller input unless the app is opened, which kind of ruins the whole point of this functionality.
25 replies
CC#
Created by Mustafa on 3/25/2024 in #help
Publishing Windows Forms App to a single .exe with no extra dependencies/dlls (Visual Studio)
No description
7 replies