Issue with love.keyboard.isScancodeDown

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

Issue with love.keyboard.isScancodeDown

Post by Fenrir »

Hey guys,

I'm currently experiencing a weird issue with this scenario:
- I first press lshift or rshift and check if they are pressed with love.keyboard.isScancodeDown, it's working without problem and returns true.
- Now, while lshift or rshift is pressed, I press for instance kp6, so kp6 is returned as pressed with love.keyboard.isScancodeDown, but now it returns false for the shift key.
- If I release the kp6 key while still holding shift pressed, it comes back returning true for shift down.

It only happens for some specific keys, I never experienced this isuue with the characters keys (as my default layout on the game is to move with wasd, and run while shift is pressed), and I noticed it as I made some tests with different layouts (kp keys to move).

Any idea if I'm doing something wrong here, or what's causing it?
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Issue with love.keyboard.isScancodeDown

Post by raidho36 »

Keyboard ghosting. Due to the way they are optimized for manufacturing costs, many key combinations simply don't work because they can not be detected by the circuit: some key combinations produce same electric pattern as other combinations, and thus are only detected as the one that "normally" produces that pattern. Ghosting patterns are model-specific and lower ghosting is a selling point of a higher class keyboards.
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

Re: Issue with love.keyboard.isScancodeDown

Post by Fenrir »

raidho36 wrote:Keyboard ghosting. Due to the way they are optimized for manufacturing costs, many key combinations simply don't work. Ghosting patterns are model-specific and lower ghosting is a selling point of a higher class keyboards.
Oh thanks, I didn't thought of it at all but it makes sense, so it's probably just an issue with my cheap keyboard, hehe... :)
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Issue with love.keyboard.isScancodeDown

Post by pgimeno »

It's unlikely to be ghosting. Ghosting can only happen if there are at least three keys pressed at a time. Ghosting is due to keyboards being built as a matrix of rows and columns, and when any three keys that form a right triangle in the matrix (two in the same row, and two in the same column) are pressed, a fourth "ghost" key is generated unless there's a diode per key (=more expensive). As Wikipedia indicates, modern keyboards detect ghosting and, rather than allow a fourth key, they block the third key.

I can't reproduce it with my keyboard, which is extremely cheap and it does have ghosting problems with certain key combos. For example, when I press 'q' and 'a' at the same time, I can't press 's'.

If it fails for just 2 keys, it's still possible that the problem is ghosting, but that would require the keyboard to close the contact of two keys at a time when pressing just one. I think it's more likely to be something else - keyboard driver being the most likely culprit. Also, the symptom would not be that the shift key stops showing as pressed, but that the newly pressed key does not show as pressed.

Here's the main.lua that I've used to check:

Code: Select all

function love.draw()
  s = ""
  if love.keyboard.isScancodeDown("rshift") then
    s = s .. "\nrshift"
  end
  if love.keyboard.isScancodeDown("lshift") then
    s = s .. "\nlshift"
  end
  if love.keyboard.isScancodeDown("kp6") then
    s = s .. "\nkp6"
  end
  love.graphics.print(s)
end
Note that in my keyboard there's ghosting between these three: when pressing any two of them, the third is blocked.

To sum up, the symptoms of ghosting are different to what you're experiencing.
User avatar
Fenrir
Party member
Posts: 222
Joined: Wed Nov 27, 2013 9:44 am
Contact:

Re: Issue with love.keyboard.isScancodeDown

Post by Fenrir »

pgimeno wrote:It's unlikely to be ghosting. Ghosting can only happen if there are at least three keys pressed at a time. Ghosting is due to keyboards being built as a matrix of rows and columns, and when any three keys that form a right triangle in the matrix (two in the same row, and two in the same column) are pressed, a fourth "ghost" key is generated unless there's a diode per key (=more expensive). As Wikipedia indicates, modern keyboards detect ghosting and, rather than allow a fourth key, they block the third key.

I can't reproduce it with my keyboard, which is extremely cheap and it does have ghosting problems with certain key combos. For example, when I press 'q' and 'a' at the same time, I can't press 's'.

If it fails for just 2 keys, it's still possible that the problem is ghosting, but that would require the keyboard to close the contact of two keys at a time when pressing just one. I think it's more likely to be something else - keyboard driver being the most likely culprit. Also, the symptom would not be that the shift key stops showing as pressed, but that the newly pressed key does not show as pressed.

Here's the main.lua that I've used to check:

Code: Select all

function love.draw()
  s = ""
  if love.keyboard.isScancodeDown("rshift") then
    s = s .. "\nrshift"
  end
  if love.keyboard.isScancodeDown("lshift") then
    s = s .. "\nlshift"
  end
  if love.keyboard.isScancodeDown("kp6") then
    s = s .. "\nkp6"
  end
  love.graphics.print(s)
end
Note that in my keyboard there's ghosting between these three: when pressing any two of them, the third is blocked.

To sum up, the symptoms of ghosting are different to what you're experiencing.
Glad to hear that it works on your side as on mine with this minimal example it still occurs, as soon as I press kp6, shift is not recognized as down anymore... So it's maybe related to drivers or to my keyboard, but at least it's something on my side. Btw I'm on Win10 with a quite common logitech keyboard (http://support.logitech.com/en_us/produ ... a-keyboard).
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Issue with love.keyboard.isScancodeDown

Post by pgimeno »

My system is Linux. Maybe other posters with the same OS as you can test and report.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Issue with love.keyboard.isScancodeDown

Post by raidho36 »

Either way there's nothing in the LÖVE source code that would warrant that kind of program behaviour. It must be your keyboard or something closely related to the keyboard.
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Issue with love.keyboard.isScancodeDown

Post by pgimeno »

No, not LÖVE's fault, but the problem is, if some of the users are going to have that same issue and it can't be avoided, that implies that he has to guard against it somehow. If it's very localized and just an outdated keyboard driver, he can tell the users to upgrade. Knowing the cause may help know what to do.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Issue with love.keyboard.isScancodeDown

Post by slime »

This page has a little inline test you can use to see if keyboard ghosting is the problem: https://www.microsoft.com/appliedscienc ... ained.mspx
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Issue with love.keyboard.isScancodeDown

Post by raidho36 »

The to-go solution that avoids all possible problems with input, literally every single one of them, is having input customizable.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 38 guests