davej Posted October 26, 2012 Share Posted October 26, 2012 http://www.w3schools.com/jsref/event_onkeypress.asphttp://www.w3schools.com/jsref/event_onkeydown.asphttp://www.w3schools.com/jsref/event_onkeyup.asp Is there any way to detect keystrokes when the user has clicked on the form and then entered keystrokes that are otherwise going to be ignored? The user has clicked on the form but not clicked into a textbox. Thanks. Link to comment Share on other sites More sharing options...
Ingolme Posted October 26, 2012 Share Posted October 26, 2012 I believe in browsers other than safari, the <body> element catches all the key events. Link to comment Share on other sites More sharing options...
Charles @ CodeConquest.com Posted October 26, 2012 Share Posted October 26, 2012 You could use jQuery and detect keystrokes on any element you want. Link to comment Share on other sites More sharing options...
niche Posted October 26, 2012 Share Posted October 26, 2012 An ajax call would take care of that problem. Link to comment Share on other sites More sharing options...
thescientist Posted October 26, 2012 Share Posted October 26, 2012 An ajax call would take care of that problem.how so? Link to comment Share on other sites More sharing options...
niche Posted October 26, 2012 Share Posted October 26, 2012 (edited) By recording the value of every keystroke in a table if you want to. Edited October 26, 2012 by niche Link to comment Share on other sites More sharing options...
thescientist Posted October 26, 2012 Share Posted October 26, 2012 I guess I'm missing some sort of requirement that the OP is looking for, cause I don't see how Ajax or databases fit in. Link to comment Share on other sites More sharing options...
niche Posted October 26, 2012 Share Posted October 26, 2012 (edited) Probably so. I wrote thinking that he meant "save". Thanks for questioning that scientist. Edited October 26, 2012 by niche Link to comment Share on other sites More sharing options...
davej Posted October 26, 2012 Author Share Posted October 26, 2012 (edited) Well, isn't AJAX irrelevant until the key capture event is proved out? I see there are some tricks to get it working: http://www.quirksmode.org/js/keys.html In a Yahoo forum I saw some bozo ask how he might create a keylogger, but the usefulness I see is creating an error beep if a "hunt and peck" typist is not typing in a valid field -- but this introduces the problem of creating an error beep. The following code detects the key event but does not identify the key in Firefox... <!DOCTYPE html><html><head><script type="text/javascript">function myFunction(e){var kc = e.keyCode;var ki = e.keyIdentifiervar kl = e.keyLocation//var c = String.fromCharCode(k);alert("Key [" + kc + " " + ki + " " + kl+ "] was pressed down");//document.getElementFromId("txt1").value = kc +" "+ ki +" "+ kl;}</script></head><body id="body1" onkeypress="myFunction(event)"> Detected keystroke: <input type="text" id="txt1"> </body></html> Edited October 26, 2012 by davej Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now