Mottie / Keyboard

Virtual Keyboard using jQuery ~
http://mottie.github.io/Keyboard/
Other
1.78k stars 723 forks source link

Getting current KeySet #504

Closed tobiasvandriessel closed 7 years ago

tobiasvandriessel commented 7 years ago

Hi @Mottie,

One last question: Is it possible to get the current active keyset?

Mottie commented 7 years ago

Hi @tobiasvandriessel!

Yes, it's not built in, maybe it should be, but you can use the "keysetChange" event to check (demo):

$(function() {

  $('#keyboard')
    .keyboard({
        layout: "international"
    })
    .on('keysetChange', function(event, keyboard, element) {
      // keyset changes before keyboard is visible
      if (keyboard.isVisible()) {
        var keyset = keyboard.$keyboard.find('.ui-keyboard-keyset:visible');
        console.log("current keyset = " + keyset.attr('name'));
      }
    });

});

or, you can check individual keysets:


keyboard.shiftActive // true when shift is active; false when not
keyboard.altActive   // true when alt is active; false when not
keyboard.metaActive  // contains the string name of the meta set when active; false when not
tobiasvandriessel commented 7 years ago

Ah thanks! That's exactly what I needed! :) Btw, can there be any more customLayouts and can the alternative keysets have names different from shift and metaX? Right now I use 3 layouts (probably going to trim that using the keysets, so using natural names instead of metaX might just come in handy) using `$.keyboard.layouts.NAME = {"default" : []}', which you strongly advise against haha.

Mottie commented 7 years ago

The meta1, meta2, .... metaN naming are only used internally by the plugin. You can change what is displayed using the display option... see the docs on how to define meta keys.

Mottie commented 7 years ago

Actually, the way the code is set up, you could add an underscore in the meta key name to describe it... something like meta0_symbols or meta1_greek_alphabet - see http://jsfiddle.net/egb3a1sk/2158/

tobiasvandriessel commented 7 years ago

Ah nice, that's really useful! I didn't realize that this was the way to go as I used the different layouts initially. Thanks again! :)

Mottie commented 7 years ago

I just released v1.26.8, and you can now name the meta keys as follows:

Sadly, I was going to add a new getKeySet function which would return the current keyset, but I forgot

tobiasvandriessel commented 7 years ago

Ah very nice! More freedom :)

Haha, don't worry about it, it's a small thing really :p

Mottie commented 7 years ago

Done!

tobiasvandriessel commented 7 years ago

Aw yeah! :D