So, I am making a pure 2D shooter in Unity, and I was thinking about cheats a little bit (Yes, I know that nobody is going to play my game but anyway).

I was wondering if you can get pressed keys directly from a keyboard (or mouse) and compare it with pressed keys in the OS.

For example, I am pressing A on the real keyboard, but my macro is also pressing B. So my program would get something like this: "keyboard: A; OS: A, B" And then my anti-cheat would say: "Oh, the inputs have differed. There is maybe a macro"

Is this possible on Windows and Linux?

有帮助吗?

解决方案

Generally, no.

Even if you're going to write a USB HID mouse/keyboard driver and your program somehow have the privilege to replace the default mouse/keyboard driver in the kernel, or even if your program actually installs itself into the bootloader as an operating system, you still won't be able to distinguish that the connected keyboard might actually be a Raspberry Pi pretending to be a keyboard, and not an actual keyboard.

其他提示

In general, if you're not programming on the bare hardware, your application is talking to the operating system and has to believe what it is told, even if the OS claims "this is actually what the hardware said". Depending on the place where a cheat inserts its artificial key presses, your application may or may not have any way of finding out whether they are genuine or fake. A cheater may even build a specialized hardware keyboard that sends key combinations faster than a player could type them.

So it's basically a matter of attack effort versus defense effort - how much effort would an attacker invest to win your game using a hard-to-detect cheat versus how much effort would you invest to prevent cheaters from winning by detecting the cheats anyway?

许可以下: CC-BY-SA归因
scroll top