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

Getting current KeySet #504

Closed
tobiasvandriessel opened this issue Jan 2, 2017 · 9 comments
Closed

Getting current KeySet #504

tobiasvandriessel opened this issue Jan 2, 2017 · 9 comments

Comments

@tobiasvandriessel
Copy link

Hi @Mottie,

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

@Mottie
Copy link
Owner

Mottie commented Jan 2, 2017

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
Copy link
Author

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

Mottie commented Jan 3, 2017

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

Mottie commented Jan 3, 2017

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
Copy link
Author

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

Mottie commented Jan 5, 2017

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

  • meta0 (still allowed), metakeys, meta_symbols, meta-greek.
  • The name must always start with meta followed by any of the following characters A-Za-z0-9_-.

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

@Mottie Mottie reopened this Jan 5, 2017
@tobiasvandriessel
Copy link
Author

Ah very nice! More freedom :)

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

Mottie added a commit that referenced this issue Jan 8, 2017
@Mottie
Copy link
Owner

Mottie commented Jan 8, 2017

Done!

@Mottie Mottie closed this as completed Jan 8, 2017
@tobiasvandriessel
Copy link
Author

Aw yeah! :D

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

No branches or pull requests

2 participants