Skip to content

Support Unicode Characters for .typeString()#276

Merged
octalmage merged 3 commits into
octalmage:masterfrom
zz85:utf8
Nov 17, 2017
Merged

Support Unicode Characters for .typeString()#276
octalmage merged 3 commits into
octalmage:masterfrom
zz85:utf8

Conversation

@zz85

@zz85 zz85 commented Mar 16, 2017

Copy link
Copy Markdown
Collaborator

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

zz85 commented Mar 17, 2017

Copy link
Copy Markdown
Collaborator Author

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

zz85 commented Mar 17, 2017

Copy link
Copy Markdown
Collaborator Author

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
Copy Markdown
Owner

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

@zz85

zz85 commented Mar 28, 2017

Copy link
Copy Markdown
Collaborator Author

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
Copy Markdown

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

zz85 commented Jun 8, 2017

Copy link
Copy Markdown
Collaborator Author

@octalmage would it be fine to merge this first?

@alexanderhoehling

Copy link
Copy Markdown

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

@lmmfranco

Copy link
Copy Markdown

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

@alexanderhoehling

Copy link
Copy Markdown

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

@profbiss

Copy link
Copy Markdown

This does not work in Windows

@yalexx

yalexx commented Oct 22, 2017

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
Owner

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

@amaramth

amaramth commented Dec 2, 2017

Copy link
Copy Markdown

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

lmmfranco commented Dec 2, 2017

Copy link
Copy Markdown

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

@georgehdd

Copy link
Copy Markdown

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

@samantrader

Copy link
Copy Markdown

@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