danzen / zimjs

ZIM JavaScript Canvas Framework - Code Creativity! Interactive Media For All.
Other
507 stars 47 forks source link

Keyboard Updating Labels #29

Closed adminy closed 4 years ago

adminy commented 5 years ago

I am trying to listen event

frame.on("keydown", function(e) {       
     if(k.selectedLabel == label1) {
         k.selectedLabel.text += e.key;
         k.selectedIndex++; //not working!
         stage.update(); 
     }
  })

Perhaps make all the functions inside keyboard available to public access. That would allow me to directly call positionBlinker() or addToLabel(e.key)

It's great that it's possible to do all this great functionality with a virtual keyboard, but not why enable the real keyboard into this as well? Thank you.

danzen commented 5 years ago

Great idea - we've been thinking that would be handy - I keep pressing keys when I see the keyboard and nothing happens... one of our users, Frank coded this initially - it was a big job (woot for Frank!) and is in part Dutch - hahaha - sigh. I guess the idea behind it is that it would be used when there is no keyboard - but in cases where there is both, you are right... it would be handy to sync them.

It looks like adding text manually like that to the label is messing it up. Will take a look at it now - might be able to patch 9.5.1 with an addChar(char, index, label) method where index defaults to the current index and label the current label - then the call from the key event will be easier. Perhaps in ZIM 10 coming out in a couple weeks we can integrate the key event to sync with a keyboard automatically. Thanks - please drop on by our Slack space at https://zimjs.com/slack where we have lots of discussion about this type of stuff!

danzen commented 5 years ago

Hi @adminy - a patch to ZIM 9.5.1 has been made so addChar(char) and removeChar() have been added. Here is an example with most keyboard functionality. We will add this to ZIM 10 - but for now, you can use the code in the example if it is helpful https://zimjs.com/explore/keyboard.html. The docs have been updated at https://zimjs.com/docs.html?item=keyboard - all the best - keep in touch!

adminy commented 4 years ago

@danzen Thank you very much. I had a modified local version of zim which fixed the issue. But that is great to hear that it has been fixed in the latest version. I should have joined the slack ages ago, ahahaha, now I will.