views:

53

answers:

6

I already used some script to implement the shortcuts in my web page

but i was wondering if could be possible to associate some combination not syncronic like Ctrl+X but more like a sequence typing 1..2..3 or any other combination to execute a script...

lets assume this example:

you have a long list with numbers:

you could type 3..5...6, so you can go to the item 356 passing trough the item 3 then 35 then 356

more or less like when you type while selecting a select box

i hope it was clear, id not easy to explain...

A: 

Yes, there are many javascript frameworks that allow you to do that. For example, check this JQuery autocomplete demo

Hope it helps ;)

rlopez13
A: 

I think you might like this one, where 'typeahead' is finding place..

http://www.pengoworks.com/workshop/jquery/autocomplete.htm

Ropstah
A: 

Recommendation: create a text input, then hook the onchange event. When the value in the box changes, navigate internally to the appropriate place on the page. Use CSS position:fixed to keep the input in the right place.

example page html:

<p id="3">
    This is paragraph 3.
</p>
...
<p id="35">
    This is paragraph 35.
</p>
...
<p id="356">
    This is paragraph 356
</p>

example html for navigation box:

<div class="navigate">
    <p>Go to: <input type="text" id="navbox" /></p>
</div>

css to put it in the upper-right corner of the screen:

.navigate {
    position: fixed;
    top: 0px;
    right: 0px;
}

javascript to perform navigation:

(function(){
    var navbox = document.getElementById("navbox");
    navbox.onchange = function(){
        var value = navbox.value;
        if (document.getElementById(value)) {
            window.location.assign("#" + value);
        }
    };
})();

Hope this helps!

jimbojw
A: 

Regarding 'keyboard shortcuts': this is a nice script which handles shortcuts, however NOT sequences (modifiers like CTRL, SHIFT do work).

If you want a sequence of key input to be handled as 'one shortcut', I think you need to write yourself a custom script. Current libraries are not supporting this.

You need to fetch all inputs within a short amount of time (reset after every keydown). When the timer ends you validate the key-sequence which was inputted against your list of shortcuts.

Ropstah
yep, i think this is the answer i was looking for... i didnt find anything out there os i might consider building the script...
camelCase
A: 

I think I understand your question. This shouldn't be too hard. I'd recommend using a library like JQuery and subscribe to the keydown even on the browser window. Then have a buffer of the 5 most recently pressed keys, after every keypress see if the 3 most recently pressed keys match any saved sequence. You could also easily time-stamp each keydown event and require all keys to be pressed within a certain time frame of each other to trigger the shortcut.

Daniel Beardsley
yep, i think this is the answer i was looking for (ropstah as well)... i didnt find anything out there os i might consider building the script...
camelCase
+1  A: 

I actually found a great script to register keystrokes sequence that is

http://boedesign.com/demos/keystrokes/

the only problem with this script is that in case you type

'man' or 'manner', it fires on 'man' because it she shortest sequence... this script maybe needs a timer...

i'm thinking also that the solution of this problem could be in a complete different approach using an autocomplete script on a invisible input field... what do you think?

camelCase