I have a request to replicate the + key as the tab key when the plus key on the number pad side is pressed.
It seems the plus key above letters where shift key is needed, and the plus key where numbers are in a keypad configuration both have a numeric number of 43.
How can I determine which + key was depressed?
Update: I was using this example, "https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_event_key_keycode" as pointed below this was not the correct way to do it.
The keycodes for each key is different. Numeric keypad = 107
, top row = 187
You can use this to verify it on your own keyboard:
$('#text').on('keydown', function (e) {
$('label').text(e.which);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="text" />
<label></label>
You can also use the key
property in modern browsers (IE9+) to detect which key was output without having to worry about exactly which keys were used to generate it:
$('#text').on('keydown', function (e) {
if (e.key == '+')
console.log('You typed a plus symbol!');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="text" />
<label></label>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With