Reputation: 1911
I am looking for a cross-browser (can be based on jquery) way to change the keypress done by a user.
Capturing it is no problem. Changing behaviour in a cross-browser compatible manner, seems to be a problem.
Essentially I need to map some extra keys to special characters. Like ctrl+alt+p should enter a special character in a text field or textarea.
Thanks,
-dennis
Upvotes: 1
Views: 2307
Reputation: 324597
I've covered a cross-browser technique for doing this before on SO: Can I conditionally change the character entered into an input on keypress?
You can adapt this for your own mappings. Also, you should use the keydown
rather than keypress
event if you're detecting keystrokes involving Ctrl or Alt, since not all browser will fire keypress events when no character is typed.
Upvotes: 0
Reputation: 1911
Inserting a text where cursor is using Javascript/jquery
http://skfox.com/jqExamples/insertAtCaret.html
Upvotes: 0
Reputation: 1186
You can capture a key press, look at the event to see if CTRL or ALT has been pressed. I assume this is pretty much what you are doing?
$(document).ready(function()
{
$("#target").keydown(function(event)
{
if (event.ctrlKey && event.altKey && event.keyCode == '80') {
alert("Ctrl-Alt-P combination");
}
}
});
Upvotes: 2