-
Notifications
You must be signed in to change notification settings - Fork 723
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
How to get the value of only the previous key? #403
Comments
Hi @knod! The
If you are wanting the $('#keyboard').keyboard({
change: function (evnt, keyboard, elem) {
var key,
lastKey = keyboard.last.key || '',
keyCode = lastKey.charCodeAt(0),
xref = {
'Bksp' : 8,
'Tab' : 9,
'Enter': 13,
'Shift': 16,
'Space': 32,
'Del' : 46
};
if ( lastKey in xref ) {
// enter => 13
keyCode = xref[ lastKey ];
}
console.log(lastKey, '=>', keyCode);
}
}); |
@Mottie: Thanks for the reply! I'm not sure what you meant by 'last "complete" input value', so for my clarification - The method you showed was interesting for fetching the keycode of a single key, but I'm making a keyboard that enters whole words, so I'm not looking for the keyCode of one key. I need to be able to detect the actual values (i.e. not the name of the key, or just what is displayed on the keyboard) of whatever key I just pressed. I need those values so I can insert them into the Ace editor we discussed in #306. The method I currently use (that you can see in the demo) works fine, even for keys like 'Enter', I just thought there might be a built in way to get the value I'm looking for. Does that clarify my question a bit? |
Hmm, why can't you use Also, you could use something like |
I guess the problem is that action keys need to be dealt with differently and that's not ideal for what I'm trying to do. It just creates more complicated code. What I want to be able to do is retrieve the last value sent to the input field (which is sometimes no value at all). There's an idea that could simplify this a lot for me and I've been looking through the code. I haven't yet parsed enough to understand what I want to try next – how do I clear the Also, do you have a gitter channel or an irc channel where we could talk real time? |
I've found the key to resetting Apparently (Edit: a part of the solution from issue #401 may have also worked, but I'm ok with mine for the moment) |
Hmm, I didn't think that would work... does the backspace and delete still work? |
The backspace key is still treated as a special case unfortunately. Not |
I added |
I'm guessing this issue has been resolved, so I'm going to close it. If you continue to have problems, please feel free to continue the discussion in this thread. |
I'm trying to get the value of the key that was just activated.
keyboard.last.key
only gives me the literal text value that appears on the visual keyboard (e.g. 'Enter'), andkeyboard.last.val
gives me the whole contents of the preview box. What property will just give me the value of just the last key pressed?Right now what I'm doing is storing the previous
.end
and using that to get a substring of.val
:I tried to use
keyboard.last.start
andkeyboard.last.end
and use those values to extract the data fromkeyboard.last.val
, but.start
and.end
currently appear to be the same as each other, no matter the length of the input that the key contains.I also tried resetting
.val
to an empty string at the end of thechange
callback to isolate any new input, but it's obviously getting its orders from somewhere else because the data of the prieview window just kept coming back.I've read some of the closed issue backlogs, but I haven't seen anything relevant yet. There must be a simpler way to do it, but so far I haven't found anything.
The text was updated successfully, but these errors were encountered: