# Alt-Key not working on Linux

**URL:** <https://forum.juce.com/t/alt-key-not-working-on-linux/15830>\
**Category:** General JUCE discussion\
**Created:** [November 3, 2015, 11:44pm UTC](https://forum.juce.com/t/alt-key-not-working-on-linux/15830 "2015-11-03T23:44:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ro0mquy](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@ro0mquy](https://forum.juce.com/u/ro0mquy)\
**Post date:** [November 3, 2015, 11:44pm UTC](https://forum.juce.com/t/alt-key-not-working-on-linux/15830/1 "2015-11-03T23:44:35Z")

</div>

Hey :)

I'm on Arch LInux with Gnome 3.18.

In my mouseDown(), ... functions the Alt-key never gets set as a modifier. I tried to find the error and after searching in the linux windowing code I think I found it. After the Alt-key was pressed and a keyboard event was send everything is fine and the flag for the Alt-key is set properly. But as soon as you move the mouse it gets unset.

The difference between the two cases is that after a keyboard event updateKeyModifiersFromSym() in juce\_linux\_Windowing.cpp is called and after a mouse event the function updateKeyModifiers() is called.

The updateKeyModifiers() triggered the Alt-key when I pressed Meta on my keyboard. It checks for a flag specified by Keys::AltMask that is set in updateModifierMappings(). The keycode for Alt gets determined by XKeysymToKeycode(display, XK\_Alt\_L), and this seems to be the source of the whole error. On my system that function call returns the same keycode for XK\_Alt\_L and XK\_Meta\_L. Based on that error also the value for Keys::AltMask gets set wrong. With my configuration everything worked correct when I set Keys::AltMask manually to 8, but I'm not sure how to make this work in a dynamic way with false output from XKeysymToKeycode().

(I'm also not 100% sure if the bitshifting "if (mapping-\>modifiermap [i \<\< 1] == altLeftCode)" is correct that way, according to https://tronche.com/gui/x/xlib/input/keyboard-encoding.html#XModifierKeymap it should be something like modifiermap[i \* mapping-\>max\_keypermod])

Already lots of thanks in advance :)

---

<div class="post-metadata">

**Author:** ![ro0mquy](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@ro0mquy](https://forum.juce.com/u/ro0mquy)\
**Post date:** [November 15, 2015, 4:03pm UTC](https://forum.juce.com/t/alt-key-not-working-on-linux/15830/2 "2015-11-15T16:03:54Z")

</div>

Could anyone reproduce this issue? Or is this a problem with my setup?

---

<div class="post-metadata">

**Author:** ![tloockx](https://avatars.discourse-cdn.com/v4/letter/t/45deac/32.png) [@tloockx](https://forum.juce.com/u/tloockx)\
**Post date:** [June 6, 2016, 9:04pm UTC](https://forum.juce.com/t/alt-key-not-working-on-linux/15830/3 "2016-06-06T21:04:44Z")

</div>

I’ve encountered the exact same issue and traced it back to the exact same location. I’ve worked around it in our code but I don’t know enough of X programming to fix it properly.

Regards,  
Thomas

---

<div class="post-metadata">

**Author:** ![tloockx](https://avatars.discourse-cdn.com/v4/letter/t/45deac/32.png) [@tloockx](https://forum.juce.com/u/tloockx)\
**Post date:** [June 15, 2016, 11:54pm UTC](https://forum.juce.com/t/alt-key-not-working-on-linux/15830/4 "2016-06-15T23:54:04Z")

</div>

I’ve spent some time fixing this. The root problem is indeed how the Modifier mask for the alt key is determined. The code is wrong.

Attached is a patch that fixes the problem.

[JUCE\_alt\_key\_windows.txt](https://forum.juce.com/uploads/short-url/7qI16XYxD7pm778SFiytLXm9xxs.txt) (1.9 KB)

cheers,  
Thomas
