diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..93b2085 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.obj +*.exe +*.zip diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..bb31123 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,7 @@ +Copyright 2022 BlueAmulet + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..2627c30 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# XInputUWPFix + +Disables the use of a game controller to navigate UWP applications. This program installs a Low Level Keyboard Hook to filter out keyboard events with VK Codes between 0xC3 and 0xDA. + +Download the latest release [here](https://github.com/BlueAmulet/XInputUWPFix/releases/latest) + +Disclaimer: Due to the use of a global hook, antivirus or anti-cheat software may complain about the use of this program. I am not responsible for any issues or damages that may result from the use of this program. + +## Installation + +A `install.bat` and `uninstall.bat` file is provided to add/remove the program to run on startup. + +## Building + +This program is designed to be built with Visual Studio 2022. Open a `x64 Native Tools Command Prompt` and run `build.bat` + +The linker options used are designed to make the exe small. diff --git a/XInputUWPFix.c b/XInputUWPFix.c new file mode 100644 index 0000000..1df4131 --- /dev/null +++ b/XInputUWPFix.c @@ -0,0 +1,38 @@ +#define WIN32_LEAN_AND_MEAN +#include + +static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) +{ + if (nCode >= 0) + { + PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT)lParam; + if (p->vkCode >= 195 && p->vkCode <= 218) + { + return 1; + } + } + return CallNextHookEx(NULL, nCode, wParam, lParam); +} + +void __stdcall EntryPoint(void) +{ + // Prevent application from running multiple times + CreateMutexA(0, FALSE, "Local\\$XInputUWPFix$"); + if (GetLastError() != ERROR_ALREADY_EXISTS) + { + // Add Low Level Keyboard Hook to filter keyboard messages + HHOOK hhkLowLevelKbd = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, 0, 0); + + // Process messages so hook works + MSG msg; + while (GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + // Cleanup + UnhookWindowsHookEx(hhkLowLevelKbd); + } + ExitProcess(0); +} diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..3b1b8d6 --- /dev/null +++ b/build.bat @@ -0,0 +1 @@ +@cl /O1 XInputUWPFix.c /link /nodefaultlib /subsystem:windows /entry:EntryPoint /debug:none /emitpogophaseinfo /emittoolversioninfo:no /merge:.pdata=.rdata kernel32.lib user32.lib diff --git a/install.bat b/install.bat new file mode 100644 index 0000000..f57401d --- /dev/null +++ b/install.bat @@ -0,0 +1,3 @@ +@echo off +reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /v XInputUWPFix /d "\"%~dp0\XInputUWPFix.exe\"" /f +pause diff --git a/uninstall.bat b/uninstall.bat new file mode 100644 index 0000000..50a52f9 --- /dev/null +++ b/uninstall.bat @@ -0,0 +1,3 @@ +@echo off +reg delete HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /v XInputUWPFix /f +pause