Printing UTF-8 Characters with accents #16

Closed
bernatbombi opened this Issue Mar 4, 2015 · 10 comments

Comments

Projects
None yet
8 participants
@bernatbombi

Hi,

when you try to typeString a character with accents, the returned string is not correct.

For example, when I try robot.typeString('à') it returns ᅢᅠ.

The same happens when I try to print an ñ, it returns ᅢᄆ.

Is there a way to make this work?

@octalmage

This comment has been minimized.

Show comment
Hide comment
@octalmage

octalmage Mar 6, 2015

Owner

There's always a way! Thanks for bringing this to my attention. I'll look into it when I get some time.

Owner

octalmage commented Mar 6, 2015

There's always a way! Thanks for bringing this to my attention. I'll look into it when I get some time.

@octalmage octalmage added the bug label Mar 6, 2015

@octalmage octalmage added the ready label Jul 18, 2015

@octalmage

This comment has been minimized.

Show comment
Hide comment
@octalmage

octalmage Jul 28, 2015

Owner

I looked into this for a few minutes and I believe the issue is in keypress.c. I'm curious if this is an issue on Windows though. I'll update when I have more time to test.

Owner

octalmage commented Jul 28, 2015

I looked into this for a few minutes and I believe the issue is in keypress.c. I'm curious if this is an issue on Windows though. I'll update when I have more time to test.

@nikersify

This comment has been minimized.

Show comment
Hide comment
@nikersify

nikersify Jul 28, 2015

robot.typeString('!@#$%^&*()') returns 1234567890 on windows, probably related.

robot.typeString('!@#$%^&*()') returns 1234567890 on windows, probably related.

@octalmage

This comment has been minimized.

Show comment
Hide comment
@octalmage

octalmage Jul 28, 2015

Owner

Uh oh! That's silly.

Owner

octalmage commented Jul 28, 2015

Uh oh! That's silly.

@Deltatiger

This comment has been minimized.

Show comment
Hide comment
@Deltatiger

Deltatiger Jul 29, 2015

Collaborator

I will check this out on windows when I have the time.

Collaborator

Deltatiger commented Jul 29, 2015

I will check this out on windows when I have the time.

@octalmage octalmage modified the milestone: First Stable Release. Jul 30, 2015

@octalmage octalmage modified the milestone: First Stable Release. Sep 22, 2015

@octalmage

This comment has been minimized.

Show comment
Hide comment
@octalmage

octalmage Dec 29, 2015

Owner

The Windows issue mentioned by @nikersify was fixed in #110.

Owner

octalmage commented Dec 29, 2015

The Windows issue mentioned by @nikersify was fixed in #110.

@amaramth

This comment has been minimized.

Show comment
Hide comment
@amaramth

amaramth Nov 23, 2016

https://github.com/octalmage/robotjs/blob/master/src/keypress.c#L224 typeString prints one byte at a time; probably that's a utf8 string & any characters outside of ascii take more than one byte; it needs to handle this.

I'd love to get this fixed, but I don't know enough C to send a good pull request. I'm sure I could hack together something bad that works, though - would that help?

amaramth commented Nov 23, 2016

https://github.com/octalmage/robotjs/blob/master/src/keypress.c#L224 typeString prints one byte at a time; probably that's a utf8 string & any characters outside of ascii take more than one byte; it needs to handle this.

I'd love to get this fixed, but I don't know enough C to send a good pull request. I'm sure I could hack together something bad that works, though - would that help?

@giacomocerquone

This comment has been minimized.

Show comment
Hide comment
@giacomocerquone

giacomocerquone Nov 29, 2016

Same problems here!
Let's try to explain it better. Let me point out that all the problems, bugs or whatever have been tested on Windows 10.

The exact problem reported from @nikersify is not present anymore. Point is that maybe the fix didn't include the keyTap function. In fact if I execute robot.keyTap('!'); it prints "1", it should be very easy, I think that the same fix used for typeString must be used over keyTap.
I would fix it by myself and submit a PR if I only be good in C... but the functions seem a bit complex to me so I trust in you 😄 @octalmage

Then skipping to the acceented words, there is a strange and inconsistent behavior between typeString and keyTap. Both of them don't work, but if I write robot.typeString('à'); and execute the script, it does nothing (it doesn't print "à" nor an error) but if I write robot.keyTap('à'); and execute, I get this:

robot.keyTap(''); // That is an unknown char for the console and it's marked by an empty square
      ^

Error: Invalid key code specified.
    at Error (native)
    at Object.<anonymous> (C:\Users\test.js:5:7)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Function.Module.runMain (module.js:575:10)
    at startup (node.js:160:18)
    at node.js:445:3

giacomocerquone commented Nov 29, 2016

Same problems here!
Let's try to explain it better. Let me point out that all the problems, bugs or whatever have been tested on Windows 10.

The exact problem reported from @nikersify is not present anymore. Point is that maybe the fix didn't include the keyTap function. In fact if I execute robot.keyTap('!'); it prints "1", it should be very easy, I think that the same fix used for typeString must be used over keyTap.
I would fix it by myself and submit a PR if I only be good in C... but the functions seem a bit complex to me so I trust in you 😄 @octalmage

Then skipping to the acceented words, there is a strange and inconsistent behavior between typeString and keyTap. Both of them don't work, but if I write robot.typeString('à'); and execute the script, it does nothing (it doesn't print "à" nor an error) but if I write robot.keyTap('à'); and execute, I get this:

robot.keyTap(''); // That is an unknown char for the console and it's marked by an empty square
      ^

Error: Invalid key code specified.
    at Error (native)
    at Object.<anonymous> (C:\Users\test.js:5:7)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Function.Module.runMain (module.js:575:10)
    at startup (node.js:160:18)
    at node.js:445:3
@amoshydra

This comment has been minimized.

Show comment
Hide comment
@amoshydra

amoshydra Dec 22, 2016

Hi,

is sending Chinese character related to this issue? Chinese character doesn't work with robot.typeString on my Windows 10 machine.

I notice that keypress.c is using keybd_event to simulate keypress.

However, I have stumbled upon a question on stackoverflow about sending unicode with c++ on Windows.

It seems to suggest that sendInput should be used instead of keybd_event for sending unicode.

Hi,

is sending Chinese character related to this issue? Chinese character doesn't work with robot.typeString on my Windows 10 machine.

I notice that keypress.c is using keybd_event to simulate keypress.

However, I have stumbled upon a question on stackoverflow about sending unicode with c++ on Windows.

It seems to suggest that sendInput should be used instead of keybd_event for sending unicode.

@dexmendonca

This comment has been minimized.

Show comment
Hide comment
@dexmendonca

dexmendonca Mar 6, 2017

Same bug on Linux

Same bug on Linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment