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

Want to programmatically click a keyboard button. #156

Closed
toketeeman opened this issue Apr 3, 2013 · 3 comments
Closed

Want to programmatically click a keyboard button. #156

toketeeman opened this issue Apr 3, 2013 · 3 comments

Comments

@toketeeman
Copy link

With a keyboard all set up and working, I would like to "type" on it from another input device instead of clicking the mouse or using touch. My code captures the device's character stream and then attempts to click the appropriate keyboard button while the keyboard is visible.

I have tried these patterns:

$("[data-value='<key-display-name>']").trigger("click.keyboard");
$("[data-value='<key-display-name>']").trigger("keypress.keyboard");

and I verified that $("[data-value='<key-display-name>']") does deliver the correct keyboard button.

But apparently this does not fire the key-handling routines that normally execute.

So what am I missing here?

@toketeeman
Copy link
Author

My meta-notation got awkwardly filtered out above. So here's an explicit example of my code:

$("[ data-value='3' ]").trigger("click.keyboard");

@toketeeman
Copy link
Author

Yep. I should have read a little deeper into the library's code ...

The solution is to either override the default keyBinding usability setting ('mousedown touchstart') to include 'click', or simply borrow that default setting as is as shown below:

Examples:

$("[ data-value='3' ]").trigger("mousedown.keyboard");
$("[ data-value='3' ]").trigger("touchstart.keyboard");

@Mottie
Copy link
Owner

Mottie commented Apr 3, 2013

Hi toketeeman!

LOL I'm glad I could help ;)

Actually if you look at the typing extension, I did it slightly different because I wanted the key to "look" like it was pressed.

// mouseover the key, add the text directly, then mouseout on the key
base.typing_simulateKey = function(el,txt){
    var e = el.length;
    if (e) { el.filter(':visible').trigger('mouseenter.keyboard'); }
    base.typing_timer = setTimeout(function(){
        if (e) { setTimeout(function(){ el.trigger('mouseleave.keyboard'); }, base.typing_options.delay/3); }
        if (!base.isVisible) { return; }
        if (!base.typing_event) {
            base.insertText(txt);
            base.checkCombos();
        }
    }, base.typing_options.delay/3);
};

base can be obtained by using var base = $('#keyboard').data('keyboard');
el is a jQuery object with the selected key $('[data-value="3"]')
txt is the actual text you want to enter

The reason I did it this way is because sometimes the text sent to the typing extension may contain keys that don't exist within the virtual keyboard.

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