-
Notifications
You must be signed in to change notification settings - Fork 90
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
Fix ROGAlly inputs #801
Fix ROGAlly inputs #801
Conversation
WalkthroughThe changes primarily focus on enhancing the Changes
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch (key) | ||
{ | ||
case 236: | ||
return; | ||
|
||
case 0: | ||
{ | ||
KeyRelease(ButtonFlags.OEM3); | ||
} | ||
return; | ||
|
||
case 56: | ||
case 166: | ||
{ | ||
// OEM1 and OEM2 key needs a key press delay based on emulated controller | ||
Task.Run(async () => | ||
{ | ||
KeyPress(button); | ||
await Task.Delay(KeyPressDelay); | ||
KeyRelease(button); | ||
}); | ||
} | ||
break; | ||
|
||
case 165: | ||
case 167: | ||
case 167: // Armory crate: Hold | ||
KeyPress(button); | ||
break; | ||
|
||
case 168: | ||
case 168: // Armory crate: Hold, released | ||
KeyRelease(button); | ||
break; | ||
|
||
default: | ||
case 56: // Armory crate: Click | ||
case 165: // Back paddles: Click | ||
case 166: // Command center: Click | ||
{ | ||
Task.Run(async () => | ||
{ | ||
KeyPress(button); | ||
await Task.Delay(20); | ||
await Task.Delay(KeyPressDelay); | ||
KeyRelease(button); | ||
}); | ||
} | ||
break; | ||
} | ||
} | ||
} No newline at end of file | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new hunk has restructured the switch statement to handle different key values. The changes include:
- Removal of cases for keys 236 and 0.
- Addition of a new case for key 167.
- Modification of the default case to handle keys 56, 165, and 166.
The changes also include the implementation of asynchronous key press and release operations, which are now accompanied by a delay. This delay is determined by the KeyPressDelay
value.
However, there is a potential issue with the use of Task.Run()
in the switch statement. Task.Run()
is used to offload work to a ThreadPool thread, but in this case, it's being used to perform a short-lived operation (pressing and releasing a key). This could lead to unnecessary overhead and potential performance issues, as creating and scheduling tasks is not free. It would be more efficient to use Task.Delay()
directly without Task.Run()
, as Task.Delay()
already returns a task that completes after a specified time delay.
Here's a suggested change:
- Task.Run(async () =>
- {
- KeyPress(button);
- await Task.Delay(KeyPressDelay);
- KeyRelease(button);
- });
+ KeyPress(button);
+ await Task.Delay(KeyPressDelay);
+ KeyRelease(button);
Committable suggestion (Beta)
switch (key) | |
{ | |
case 236: | |
return; | |
case 0: | |
{ | |
KeyRelease(ButtonFlags.OEM3); | |
} | |
return; | |
case 56: | |
case 166: | |
{ | |
// OEM1 and OEM2 key needs a key press delay based on emulated controller | |
Task.Run(async () => | |
{ | |
KeyPress(button); | |
await Task.Delay(KeyPressDelay); | |
KeyRelease(button); | |
}); | |
} | |
break; | |
case 165: | |
case 167: | |
case 167: // Armory crate: Hold | |
KeyPress(button); | |
break; | |
case 168: | |
case 168: // Armory crate: Hold, released | |
KeyRelease(button); | |
break; | |
default: | |
case 56: // Armory crate: Click | |
case 165: // Back paddles: Click | |
case 166: // Command center: Click | |
{ | |
Task.Run(async () => | |
{ | |
KeyPress(button); | |
await Task.Delay(20); | |
await Task.Delay(KeyPressDelay); | |
KeyRelease(button); | |
}); | |
} | |
break; | |
} | |
} | |
} | |
\ No newline at end of file | |
} | |
// get button | |
var button = keyMapping[key]; | |
switch (key) | |
{ | |
case 167: // Armory crate: Hold | |
KeyPress(button); | |
break; | |
case 168: // Armory crate: Hold, released | |
KeyRelease(button); | |
break; | |
default: | |
case 56: // Armory crate: Click | |
case 165: // Back paddles: Click | |
case 166: // Command center: Click | |
KeyPress(button); | |
await Task.Delay(KeyPressDelay); | |
KeyRelease(button); | |
break; | |
} | |
} | |
} |
Summary by CodeRabbit