jmoenig / Snap

a visual programming language inspired by Scratch
http://snap.berkeley.edu
GNU Affero General Public License v3.0
1.51k stars 745 forks source link

Dead key input not working (Mac) #4

Closed MMSequeira closed 5 years ago

MMSequeira commented 11 years ago

At least in Mac OS X, non-ASCII characters cannot be input the usual way (i.e., ´+a to get á). All non-ASCII characteres must thus be pasted from elsewhere.

bl-nero commented 9 years ago

Geez, it looks like this bug has been there for a while. As I'm going to conduct a short programming course using Snap! later this year, I'd be willing to fix it myself.

Should I send a normal pull request, or follow the procedure outlined in the contributor's guide? I'm asking because the guide looks highly unorthodox, and I'm not sure if it's up to date.

jmoenig commented 9 years ago

It would be wonderful if you cold find a fix for this, @bl-nero ! Please do issue a pull-request if you mange to fix it, pull-requests on Github are fine. The guidelines are pre-Github (but still current as far as the style part goes. Also, don't use the current beta version of JSLint to test your code, use old.jslint.com instead). Thanks!

ghost commented 9 years ago

This is a problem with Morphic.js. The WorldMorph keyboard event listener should be changed. I've forked the Morphic.js repo.

jmoenig commented 9 years ago

cool. Does it work in your fork? Can you explain what you had to change to make it work? Thanks!

bl-nero commented 9 years ago

@luis140219 I took a look at the list of commits in your fork, and it looks like the changes that you have made are unrelated to this bug. Are you sure that you have pushed everything?

introlinux commented 9 years ago

This problem is in Linux too with spanish keyboard, no accents in inputs blocks, for example, when you make an "ask" block or when your program is running the user can not write the properly answer.

It would be great if someone fix it.

DarDoro commented 8 years ago

Root of this problem is browsers javascript KeyboardEvent. Sequence [Alt] + key , generates [Alt] + [Ctrl] + key event. In "morphic.js" this is mishandled as [Ctrl] + key and prematurely disposed. To prevent this, test for "ctrlKey" should be expressed as "event.ctrlKey && (!event.altKey)". Procedures affected (line numbers for source downloaded from http://snap.berkeley.edu/snapsource/snap.zip):

This fix effectively disables [Ctrl] [Alt] + anything (acts as [Alt]...) in favor of proper handling of diacritics. The required changes are minimal so should I made pull request? Works with Chrome, Opera, Internet Explorer, Edge on Windows 10.

jmoenig commented 8 years ago

Awesome analysis. Yes, please issue a pull-request, thank you!

cycomachead commented 8 years ago

:+1: This is excellent! :smile:

DarDoro commented 8 years ago

Made pull-req #1039

jmoenig commented 8 years ago

Okay, I'm trying your pull request right now. On my Mac Manuel's use-cases still don't seem to work, but then again I'm not using ctr + alt + key strokes to enter them (but that doesn't seem to be doing much on my Mac keyboard either, so I'll check Windows next)

DarDoro commented 8 years ago

@jmoenig This was solution for #1036, closed as known limitation/duplicate of this one. Local diacritics (polish), with proper keyboard driver (polish programmer) are entered by [Alt] + key. As I'm not having any Mac OSX box at hand ;( you may try to add morphic.js

canvas.addEventListener( "keydown", function (event) { this.inspectKeyEvent(event); console.log( event);

to examine/post details of keyboard event in your environment.

In SNAP source there is a __MACOSX folder with some derivatives of *.js. I'm not aware of purpose or need of modification of these files.

cycomachead commented 8 years ago

In SNAP source there is a __MACOSX folder with some derivatives of *.js. I'm not aware of purpose or need of modification of these files.

Where did you get this source copy? Either way, you can ignore them.

cycomachead commented 8 years ago

So, I'm beginning to think we can't fix this on OS X....at least not with the current implementation of text input... However, if #1036 Works for windows, then that still counts for progress!

I've been logging various combos of key events in keypress/keyup/keydown in Chrome and Safari and I can't get anything that resembles native OS X diacritics. I was also looking at this page and found some weird differing behavior between Safari and Chrome: http://www.bloggingdeveloper.com/post/KeyPress-KeyDown-KeyUp-The-Difference-Between-Javascript-Key-Events.aspx In Safari, it won't even show you the partial inputs, like ¨, but Chrome will.

Update: I haven't read through this all, but this project seems to be running into similar issues, also without much progress. There's some code and discussion in this thread: https://github.com/kanaka/noVNC/issues/21

DarDoro commented 8 years ago

Pull request #1103: Enable IME Composing for some diacritics on Mac OS #4 X & ideograms #1047 & Android virtual keyboard

Some keyboard layout on Mac OS X activates, so called, IME Composing for entering diacritics with "dead key". During "composing", usual keyboard events (keydown, keypress) are useless. Keystrokes are modified by browser or even discarded. Composition results are supplied to JS by appropriate events (compositionstart, compositionupdate,compositionend). Composition events are fired , only for text input (according DOM level 3 events specification). Changes,"morphic.js": 1) added "compositionend" event handler to hidden input field "VirtualKeyboard" (used so far for touch devices input) and send simulated kypress to Morphic canvas 2) enabled "VirtualKeyboard" by default, not only for touch devices

Side effects of this update is ability to enter ideograms on Mac OS X & Windows. Also Android virtual keyboard can be used now.

Tested with: Mac OS X : Safari - English Extended, US International , Japan Hiragana keyboard layout Windows 10: Chrome 47, IE11 - Japan Hiragana layout Android 4.4: Chrome ??, virtual keyboard

User experience may be slightly disturbed. On Android, dictionary suggestion must be accepted with extra click. Hiragana input must be ended with [Enter].

There are also possible enhancements: handling of "compositionupdate" can provide better visual feedback. Initial value of the input field should be copied to VirtualKeyboard to provide more context for IME. Edit field (VirtualKeyboard) can be styled to accept number, letters or disable dictionary support.
osxscreen

cycomachead commented 8 years ago

Wow!! This is great!!! How did I not come across the compositionend event?!

This does break copying and pasting for me, but perhaps this just means we should move the C&P to the virtual keyboard somehow.

Also, is there ever a reason to turn the keyboard off? We could simplify things by removing that code.

jmoenig commented 8 years ago

Yes, we should fold C&P into the virtual keyboard and get rid of one of the hidden DOM elements. Then we can remove the option in MorphicPreferences as well. This is cool!

bromagosa commented 8 years ago

I've just noticed the dead key is not working for me on Firefox on Debian, Firefox on Ubuntu or Chrome on Ubuntu. It does work on Chrome on Debian.

However, @DarDoro's patch fixes it everywhere for me, except for Chrome on Ubuntu.

jmoenig commented 5 years ago

the issue of entering accented and multi-byte characters into input fields has now been resolved as of https://github.com/jmoenig/Snap/tree/v5.0.6