By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,688 Members | 1,936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,688 IT Pros & Developers. It's quick & easy.

Key logger

P: 2
Hello,

I was wondering if it is possible to create a key logger program that utilize the javascript programming language. Well, the entire program itself wouldn't be coded in javascript, only the client-side of the program. So on the client, is it possible to use javascript to invisibly record what a user inputs in the address field, and other website forms, then that data would be sent to the server to be stored in a text file?


p.s. I'm trying to create this security system, that has the capacity to build psychological profiles of users based on the websites they go, and the key logger component would provide the system access to the user's data, to be used for processing.
Jan 13 '10 #1
Share this Question
Share on Google+
5 Replies


gits
Expert Mod 5K+
P: 5,390
of course .... it is possible ... but you would only be able to record the keypresses that are done while the webpage has focus ...

kind regards
Jan 13 '10 #2

P: 16
Here are two ways. The first code captures everything the user types. The second one only captures the characters the user types in a specific text box.
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. var keystrokes = "";
  3. if (navigator.appName == 'Netscape') {
  4.     window.captureEvents(Event.KEYPRESS);
  5.     document.onkeypress = netscapeKeyPress;
  6. }
  7. function netscapeKeyPress(e) {
  8.     keyCode=e.which;
  9.     handleEvent(keyCode);
  10. }
  11. function microsoftKeyPress() {
  12.     keyCode = window.event.keyCode;
  13.     handleEvent(keyCode);
  14. }
  15. function handleEvent(keyCode) {
  16.     keystrokes += String.fromCharCode(keyCode);
  17. }
  18. </script>
  19. <body onKeyPress="microsoftKeyPress();">
  20.  
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. var keystrokes = "";
  3. function captureKey(e) {
  4.     var key = window.event ? e.keyCode : e.which;
  5.     var keychar = String.fromCharCode(key);
  6.     keystrokes += keychar;
  7. }
  8. </script>
  9.  
  10. <input type="text" onkeypress="captureKey(event);" />
  11.  
Jan 13 '10 #3

gits
Expert Mod 5K+
P: 5,390
the second script would even capture all keystrokes when you would add the listener to the document like this:
Expand|Select|Wrap|Line Numbers
  1. var keystrokes = "";
  2.  
  3. function captureKey(e) {
  4.     var key = window.event ? e.keyCode : e.which;
  5.     var keychar = String.fromCharCode(key);
  6.     keystrokes += keychar;
  7. }
  8.  
  9. document.onkeypress = captureKey;
and it should be preferred to use addEventListener() / attachEvent() to add the listerens ... like here for FF for example:
Expand|Select|Wrap|Line Numbers
  1. document.addEventListener('keypress', captureKey, true);
kind regards
Jan 14 '10 #4

acoder
Expert Mod 15k+
P: 16,027
Also note that the first script is badly out of date to the point of almost being useless.
Jan 15 '10 #5

P: 2
Thanks so much for the insight. More questions coming soon!!

best regards,
Jan 15 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.