PyUserInput icon indicating copy to clipboard operation
PyUserInput copied to clipboard

printing @ signs

Open pikusinski opened this issue 10 years ago • 11 comments

I have a problem printing the "@" sign when using type_string. Anyone knows why? I have UTF-8 as encoding.

pikusinski avatar Nov 06 '13 11:11 pikusinski

Can you describe the error? Does it generate a traceback? I can test it myself shortly.

SavinaRoja avatar Nov 06 '13 11:11 SavinaRoja

Oh sorry. Sometimes I forget that people can't read my mind.

There is no error what so ever. It only prints a double quote

pikusinski avatar Nov 06 '13 11:11 pikusinski

Hmmm, I am able to print that symbol on my computer with pykeyboard without issue. So you say that it prints a double quote instead of the @ symbol? This might be interesting. Could you copy the output of xmodmap -pke here?

SavinaRoja avatar Nov 06 '13 15:11 SavinaRoja

Oh sorry. Forgot to say that this is a windows problem.

pikusinski avatar Nov 07 '13 07:11 pikusinski

It looks like perhaps you have an American keyboard but a UK layout (or vice versa?).

SavinaRoja avatar Nov 07 '13 16:11 SavinaRoja

I have a Swedish keyboard. But that gave me some hints. Will check it out.

pikusinski avatar Nov 11 '13 07:11 pikusinski

So I've played around a bit and I see that when I'm using swedish as keyboard layout in windows, it prints a ". But when I change to english (US), it prints a @ sign.

Note that it's the target application that needs to have this keyboard setting. The rest of the applications don't need to change theirs.

So my question is, how can I gt around this problem?

pikusinski avatar Nov 11 '13 15:11 pikusinski

A quick fix I've made was to let the program press shift + alt at the same time, which changes the keyboard layout. Then when typing is done, it changes back

pikusinski avatar Nov 11 '13 15:11 pikusinski

PyKeyboard relies on the VkKeyScan method of win32api to convert a character to its appropriate windows keycode. http://docs.activestate.com/activepython/2.4/pywin32/win32api__VkKeyScan_meth.html So it might seem that for certain layouts, this function is not working properly?

SavinaRoja avatar Nov 12 '13 01:11 SavinaRoja

 I know that mac uses virtual scan codes, which are identical across layouts. It seems the windows api is giving you the raw hardware code.‎ Sent from my BlackBerry 10 smartphone. From: Paul BartonSent: dinsdag 12 november 2013 02:30To: SavinaRoja/PyUserInputReply To: SavinaRoja/PyUserInputSubject: Re: [PyUserInput] printing @ signs (#19)PyKeyboard relies on the VkKeyScan method of win32api to convert a character to its appropriate windows keycode. http://docs.activestate.com/activepython/2.4/pywin32/win32api__VkKeyScan_meth.html So it might seem that for certain layouts, this function is not working properly?

—Reply to this email directly or view it on GitHub.

pepijndevos avatar Nov 12 '13 08:11 pepijndevos

I did find reference to another function that utilizes layout information http://msdn.microsoft.com/en-us/library/windows/desktop/ms646332(v=vs.85).aspx in the windows API for C++. It is my understanding that the python API is linking to the C++ one; this function is not documented in the python API.

Both of VkKeyScan and VkKeyScanEx are meant to return 2 bytes of information (a short integer); the rightmost (low-order) byte is a statemask of modifiers, and the leftmost (high-order) is a virtual keycode for the character. The documentation for win32api.keybd_event is spartan and relatively unhelpful, but it does suggest a few different avenues to pursue for testing. I may need to do some direct testing and digging through the windows api C++ source code to properly understand how to account for different keyboard layouts.

We may eventually need to get a bit more elaborate...

SavinaRoja avatar Nov 12 '13 20:11 SavinaRoja