love.keyboard.isDown doesn't work for Alt Gr

Issue #1281 new
William Dyce
created an issue

Hi all,

I have a French (AZERTY) keyboard with an "Alt Gr" key instead of a right alt. When I press this key love.keypressed is called, and when I release it love.keyreleased is called. However love.keyboard.isDown("ralt") always returns false.

This is pretty easy to monkey-patch but it's a bit of a bummer.

Minimal code to reproduce:

local ralt = false

love.keypressed = function(key)
  if key == "ralt" then
    ralt = true
  end
end

love.keyreleased = function(key)
  if key == "ralt" then
    ralt = false
  end
end

love.update = function()
  if ralt ~= love.keyboard.isDown("ralt") then
    print("oh no!")
  end
end

Comments (3)

  1. Raidho

    The functions you use are layout-dependant and you generally shouldn't use them. You should instead use scancodes, those are tied to hardware.

    I guess the SDL keyboard event returns SDL_RALT when AltGr is pressed, but since it's not Right Alt it doesn't update its state, and so the Right Alt was never actually pressed so it's false.

  2. William Dyce reporter

    Well the in-game options allow players to rebind their control so it's not really an issue - with this feature in place the "what you see is what you get" of layout-dependant control is actually not a bad thing.

    Whatever the case the issue stands: there is inconsistent behaviour between isDown and keypressed when it comes to the Alt Gr key.

  3. Gabe Stilez

    Here's my experience:

    I use a hungarian keyboard with hungarian layout (qwertz in general). I also have an Alt Gr key.

    It gets mapped to the combination 'lctrl' + 'ralt', both with keycodes AND scancodes, which is a bummer only because the scancode technically should correspond to the physical layout... but that's windows for you.

    In any case, for me, the callbacks and love.keyboard.isDown / isScancodeDown functions work as expected, that is, the above way; consistently they return true for ralt.

    Here's my code: (also keep it in mind that you need to enable your console with a conf.lua in most cases, otherwise nothing will print.)

    local ralt = false
    
    love.keypressed = function(k,s)
      print('callback press',k,s)
    end
    
    love.keyreleased = function(k,s)
      print('callback release',k,s)
    end
    
    love.update = function()
      print(love.keyboard.isDown('ralt'))
      print(love.keyboard.isScancodeDown('ralt'))
    end
    
  4. Log in to comment