Sunday, August 14, 2016

2d - How to avoid ghosting when pressing multiple keys?


I am working on a 2d side-scrolling pc game that uses SFML game library. The problem that I am not able to solve is that in many keyboards combination of three or more keys (like w + d + k) is not working. Is there any way to solve this issue?




Answer



You can't. At least, not as a game developer.


As a gamer, you can purchase more expensive keyboards with "anti-ghosting" features, but otherwise the limitation is part of the hardware itself, so there's nothing you can do in software to solve it.


Check out this demo page to see how keyboard ghosting works, plus a demo: https://web.archive.org/web/20150429053827/http://www.microsoft.com/appliedsciences/antighostingexplained.mspx


So your best bets are:



  • Don't use a control scheme that requires too many simultaneous key presses

  • Use game pads if they are available

  • Let the player remap the keys so they can find a non-ghosting set of keys for their hardware

  • If you must, stick to the left side of the keyboard (around WASD) because keyboards tend to avoid ghosting around here



Historically, many PC games used modifier keys (Ctrl, Alt, Shift) as part of their controls because these keys were wired to handle being pressed together with other keys, to avoid ghosting. This practice sort of fell out of favour during the 90s because the modifier keys were being used more and more by the OS, which would interfere with the game.


Later, certain genres of games had their controls coalesce around key clusters, most notably the FPS genre around WASD + mouse, but another example would be Japanese indie games around ZXC + arrows. In a self-fulfilling manner, since most games used these clusters, keyboard manufacturers also made sure that ghosting was minimised around this area, so if you stick to the same controls that other popular games use, you will also avoid ghosting.


Looking at your example, W and D are fine but K is not; are you by any chance using K as a directional control? If so, consider using the arrow keys instead.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...