Closed xeechou closed 8 years ago
You are printing uint32_t as %c. I'm not sure what you mean by "random key", but the keysym isn't ASCII character.
I used %c
for 'pretty print', I used %d
before, the result is similar, the values of sym
was not consistent while I didn't press any key(but modifiers). that is, meaning of "random key" means I got random value for sym
.
These are the sample output of log:
KEYKEY: modifiers: 4, leds:0, key: ã
KEYKEY: modifiers: 12, leds:0, key: é
KEYKEY: modifiers: 4, leds:0, key: ã
KEYKEY: modifiers: 12, leds:0, key: é
KEYKEY: modifiers: 4, leds:0, key: ã
KEYKEY: modifiers: 12, leds:0, key: é
KEYKEY: modifiers: 0, leds:0, key:
KEYKEY: modifiers: 0, leds:0, key:
KEYKEY: modifiers: 0, leds:0, key:
KEYKEY: modifiers: 0, leds:0, key:
KEYKEY: modifiers: 4, leds:0, key: ã
KEYKEY: modifiers: 12, leds:0, key: é
KEYKEY: modifiers: 12, leds:0, key:
What exactly is inconsistent here? We know %c
isn't going to work at all on uint32_t
so you'll get random memory differencing that as a char
(essentially 1 byte).
But the number, the %d
looks fine to me?
_Edit: Don't tell me you expected naively using %c
was going to work on a uint32_t
storage type..._
No, the %d won't work either, I used %c just to see if [a-z]
are mapped correctly, the inconsistent means if I don't press any key sym but modifiers for two times, the sym
values are different.
KEYKEY: modifiers: 0, leds:0, key: 97 //I pressed 'a'
KEYKEY: modifiers: 0, leds:0, key: 98 //I pressed 'b'
KEYKEY: modifiers: 0, leds:0, key: 99 //I pressed 'c'
KEYKEY: modifiers: 0, leds:0, key: 100 //I pressed 'd'
KEYKEY: modifiers: 0, leds:0, key: 101 //I pressed 'e' they all correct
KEYKEY: modifiers: 4, leds:0, key: 65507 //I pressed 'ctrl'
KEYKEY: modifiers: 8, leds:0, key: 65513 //I pressed 'alt'
KEYKEY: modifiers: 12, leds:0, key: 65507 //I tried to press ctrl+alt+esc to quit program
KEYKEY: modifiers: 12, leds:0, key: 65307 //I guess
when I pressed ctrl
, the sym
is 65507, when I pressed alt
, the sym
is 65513. Just wondering that shouldn't the sym
be the same in two cases, because I didn't press any sym
at the times?
No, ctrl and alt are different keys, of course they will have different symbol.
Isn't there a function to print a nice character that's associated with the uint32_t
value?
I see, I thought keysym is independent from modifiers, thanks.
@Earnestly xkb_keysym_get_name and xkb_keysym_to_utf8/xkb_keysym_to_utf32, depending what you want.
Hi,
I am writing code to test key press event, and I found if I only pressed modifiers, I would get random key symbol, the code is here:
In the log file, I found the last
key
field infprintf
is random key if no key is pressed. Is it normal?