Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Unicode Characters for .typeString() #276

Merged
merged 3 commits into from
Nov 17, 2017
Merged

Conversation

zz85
Copy link
Collaborator

@zz85 zz85 commented Mar 16, 2017

Here's is preliminary patch for support unicode characters in robotjs for .typeString().

robot.typeString('Àçćéñtéd'); // works
robot.typeString('你好吗?'); // works
robot.typeString('😆💩🌺😍👍😠🐠😝😢🤣😢🦑'); // works

This fixes #16 #30

It has does simple UTF-8 parsing (without validation) and I have tested this with Chinese and accented characters [edit: and emjios] on MacOS.

However, I have not figured how to have emojis sending yet nor have I have tested it on other platforms although I've tried to make the code changes minimal here.

- rudimentary UTF-8 parsing
- tested with Chinese characters
- doesn't work with emojis yet
- tested on mac but not other platforms
- Try windows-friendly 32 unsigned integer type called unsigned long
@zz85
Copy link
Collaborator Author

zz85 commented Mar 17, 2017

After some amount of trial and error, it seems CGEventKeyboardSetUnicodeString expects a UTF-16 character instead, will be update this PR once I get it working...

@zz85
Copy link
Collaborator Author

zz85 commented Mar 17, 2017

Update: After decoding, characters are re-encoded into UTF-16 to be used with CGEventKeyboardSetUnicodeString. This fixes all sending codepoints higher than 0x10000. That means emojis now work :)

@octalmage
Copy link
Owner

This is amazing, thank you so much for looking into this. I'll check it out soon!

@zz85
Copy link
Collaborator Author

zz85 commented Mar 28, 2017

Yay, I think this is the smallest set of changes to get unicode working but I'm pretty sure there's a better way to structure this. Let me know if you've a way to make it better :)

@alexanderhoehling
Copy link

Is it possibile to create a new release for that, there is need in a project and i think more people want to have this support

@zz85
Copy link
Collaborator Author

zz85 commented Jun 8, 2017

@octalmage would it be fine to merge this first?

@alexanderhoehling
Copy link

of course ... do you know when this will be done?

@lmmfranco
Copy link

@octalmage What about merging this PR? Seems a nice addition.

@alexanderhoehling
Copy link

I do not have a problem if you merge this pr with #326

@profbiss
Copy link

This does not work in Windows

@yalexx
Copy link

yalexx commented Oct 22, 2017

Hello guys, how can i run this branch locally. I know its noob question but do i have only to pull it or this keypress.c must be compiled. And what is the git command to pull this specific branch.

@harrysarson
Copy link
Contributor

See https://help.github.com/articles/checking-out-pull-requests-locally/#modifying-an-inactive-pull-request-locally.

Which boils down to running the following from your shell from within a clone of the robotjs repository.

git fetch origin pull/276/head:unicode
git checkout unicode

@octalmage octalmage merged commit d021733 into octalmage:master Nov 17, 2017
@octalmage
Copy link
Owner

Sorry everyone! I've been busy, but thanks again! I'll get a new release out this weekend.

@amaramth
Copy link

amaramth commented Dec 2, 2017

I don't know the best way to do this, but I grabbed HEAD and put it in a release so that I could use this library. https://www.npmjs.com/package/robotjs_head_2017-12-01 . And it works! Thank you zz85 for the fix.

@lmmfranco
Copy link

lmmfranco commented Dec 2, 2017

@alice0meta you can use a fork directly as npm dependency. https://docs.npmjs.com/cli/install

@georgehdd
Copy link

@octalmage - any chance you will be releasing an official fix soon?

@samantrader
Copy link

@zz85 hi how can use your change that support utf in windows version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Printing UTF-8 Characters with accents
10 participants