Incorrect key pressed when using unicode_char_down
When running the following code...
let mut ctx = Context::new().unwrap();
ctx.unicode_char_down('s').unwrap();
ctx.unicode_char_up('s').unwrap();
On my computer it presses the ; key, even though it's supposed to press the s key.
However the following code works fine:
let mut ctx = Context::new().unwrap();
ctx.ascii_char_down(b's').unwrap();
ctx.ascii_char_up(b's').unwrap();
I'm using Linux (X11).
I'm commenting to say that I have seen this and I've been thinking about it. I'm really not sure and unfortunately it's going to be a while before I have the time to troubleshoot this properly. Out of curiosity, what do you get from this?
let mut ctx = Context::new().unwrap();
for c in b' '..=b'~' {
ctx.ascii_char(c).unwrap();
ctx.ascii_char(b' ').unwrap();
ctx.unicode_char(c as char).unwrap();
ctx.ascii_char(b'\n').unwrap();
}
This is what I get:
! !
" Q
# #
$ $
% %
& &
' q
( (
) )
* *
+ }
, w
- '
. e
/ [
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
: Z
; z
< W
= ]
> E
? {
@ @
A A
B N
C I
D H
E D
F Y
G U
H J
I G
J C
K V
L P
M M
N L
O S
P R
Q X
R O
S :
T K
U F
V >
W <
X B
Y T
Z ?
[ -
\ \
] =
^ ^
_ "
` `
a a
b n
c i
d h
e d
f y
g u
h j
i g
j c
k v
l p
m m
n l
o s
p r
q x
r o
s ;
t k
u f
v .
w ,
x b
y t
z /
{ _
| |
} +
~ ~
P.S. I prefer to use char::from(c) for converting from a u8 -> char, but it makes no difference in this test.
You wouldn’t happen to be using Dvorak by any chance? 😉
Keyboard layout probably should have been my first question. I will admit that I only tested this with Qwerty.
Yes I am a Dvorak Master Race™. So it seems that tfc isn't taking into account keyboard layout.
This is what I get when I use QWERTY:
! !
" "
# #
$ $
% %
& &
' '
( (
) )
* *
+ +
, ,
- -
. .
/ /
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
: :
; ;
< <
= =
> >
? ?
@ @
A A
B B
C C
D D
E E
F F
G G
H H
I I
J J
K K
L L
M M
N N
O O
P P
Q Q
R R
S S
T T
U U
V V
W W
X X
Y Y
Z Z
[ [
\ \
] ]
^ ^
_ _
` `
a a
b b
c c
d d
e e
f f
g g
h h
i i
j j
k k
l l
m m
n n
o o
p p
q q
r r
s s
t t
u u
v v
w w
x x
y y
z z
{ {
| |
} }
~ ~
Things are starting to settle down a bit so I finally had the chance to investigate this properly today. Although I wasn't able to reproduce the problem unfortunately.
- I fired up an Ubuntu 20.04.3 VM using X11.
- I ran the example using the default
English (US)layout and found that the characters on the left always matched the characters on the right. - I switched to
English (Dvorak)and found that theascii_charcharacters were jumbled up while theunicode_charcharacters were in ASCII order.
This is expected behaviour. unicode_char('s') should always type an s no matter what the keyboard layout is. ascii_char(b's') will press the key in the position of an s on a QWERTY keyboard. When using the QWERTY layout, this results in an s being typed. However, when using Dvorak, pressing the s key results in an o being typed. I found that ascii_char(b's') typed an o when using Dvorak.
Can you tell me more about your setup? I might need to use a different distro or use a different method for changing the layout.