I have a question regarding the char codes for keyboards. I was reading this article
This has a bunch of key codes.I want to check what key code to use when user presses the alt and down arrow.I have to create dropdowns like comboboxes which displays the list when user presses alt and down key.
Thanks
The keyboard event has event.altKey to indicate whether alt was pressed.
Read https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent for more information.
The easiest way to find out any key code is to put console.log(event.data.keyCode) into your event function.
For example key code for "Alt + Down" is 4456488.
Related
I am working in sale order line and currently by pressing "Enter" key in one2many field it is creating new line, but I want to do some changes so Enter key work as TAB key ,It means if I pressed Enter key then insted of creating new line it should focus on next field of one2many.
Example:
There are 4 fields in one line so when I pressed enter key it should switch to next field in same line insted of creating new line.
I am giving answer to my question .. Actually I tried and found one solution from the following link:
From odoo forum
There are some issue which I found in that answer but didn't able to solve that :(
Issues are:
(1) I make change in base model of web in that "view_list_editable.js" as told in this link insted of my custom model.
(2) Also when any read-only fields is there in between One2Many visible fields then this solution is not working..
Changes "Enter" key behaviour in UI form: jump to next input field instead of doing nothing.
Just use web_returnkey module (by Vadim)and take a look at this answer in ODOO Forum https://www.odoo.com/forum/help-1/how-to-make-the-enter-key-work-as-tab-key-in-form-view-134811 :
https://www.youtube.com/watch?v=hdD-C2ppsyQ
I have an input box and want to adjust the value when a key is pressed.
'keypress .comment-input': 'onCommentInputKeyBlur',
When a key is pressed, a class is added to the html element to reflect the changes.
onCommentInputKeyBlur: function(ev) {
var $form = $('#comment-submit');
if (ev.which) {
$form.addClass('focused');
} else if (!$(ev.currentTarget).val()) {
$form.removeClass('focused');
}
},
However, this doesn't detect special keys being pressed (ie when a user presses ctrl+v for a paste, it's not detected and the formatting is therefore wrong).
Using keyup and keydown halfway solve the problem, but formatting is wrong for a brief second:
Keydown -> the value isn't supposed to change until an actual value is entered through a keypress, but it changes right when ctrl is hit instead of waiting for the second key
Keyup -> new value is briefly pasted over the previous one while waiting for the key to actually be released.
Is there a better way to about solving this? Ideally, I would like to detect if the key entered does actually produce a value and is not simply a special key.
Look into the onchange event. It is fairly well supported and may solve your problem.
What is the ultimate goal of this functionality? perhaps there is a better approach.
If you insist on doing this via keypress event, then you can simply check event.keyCode and filter out the few keycodes that dont change anything, such as shift, control, alt.
So I've got this textarea which listens for Enter keypress event. But I only want it to respond to the Enter key being pressed on the number pad not the one next to the letters.
What's a method I can use?
Both keys trigger the exactly same events with the same key code (13). It's not possible to differ between them in JavaScript.
There is no different keyCode for nomal enter and enter on keypad. Its 13 in both cases
http://unixpapa.com/js/key.html
They actually do the same thing and are indistinguishable
How can i capture the following keys in Textbox using JavaScript?
Ctl + a
Ctl + c
Ctl + v
Following is the original Situation.
I have three Textboxes for Phones numbers. Textbox1 max length is 3 , 2nd's is 3 and 3rd is 4. When user types three digits in TextBox1 the cursor moves automatically to TextBox2 same thing happens with TextBox2 as well as TextBox3. I am handling this functionality in keyup event. Now, I am parallely using your code. But it moves in keyup event as well. This case happens when all TextBoxes are filled. Now suppose I am in TextBox1 and presses Ctl + A . This moves the user to third TextBox(unacceptable case). This is the issue.
Use the select, copy and paste events respectively. Pretty much universally supported these days.
var textBox = document.getElementById("textBoxId");
textBox.onpaste = function() {
alert("paste");
};
Likewise for the other events. Demo here: http://jsfiddle.net/timdown/EC2Hf/
And what about right click, osx that does not use control, the edit copy option on the browser, the button on my old keyboard, etc?
There is more than just key presses.
That said, most browsers support
oncopy and onpaste events.
You would have to first check if the ctrl button was clicked and then the correspnding letter keys. This link may help you out
is it possible to show/hid a div on a webpage if say three keys are pressed in the correct order on a normal keyboard....
Im trying to hide my login div in drupal and only want it to show if I press say three keys on the keyboard. Dosnt matter if it shows up in source.
any thoughts/links?
cheers
You can try js-hotkeys.
jQuery.Hotkeys plugin lets you easily add and remove handlers for keyboard events anywhere in your code supporting almost any key combination. It takes one line of code to bind/unbind a hot key combination.
Example: Binding 'Ctrl+c'
$(document).bind('keydown', 'ctrl+c', fn);
Next step is to show/hide your div in the function you pass in.
You have to intercept the keypress event (or keyup) and then check which key was pressed (see jQuery Event Keypress: Which key was pressed?)
To handle a key sequence you have to store the pressed key codes into an array and then check it against your defined sequence.
This "cheat code" jQuery plugin should make what you're asking especially simple.
If you poll for key presses and store them in array then match that with the correct array once this happens show the div then clear your stored array. Close the div and start the process again.