Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,906
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Ah, a bit over my head, but:-

    Code:
    <script type = "text/javascript">   
    
    var counter = [];
    for (var i =0; i <=25; i++) {
    counter[i] = 0;  // initialise all 26 array elements which are 0-25
    }
    
    function handleKeyPress(evt) {   
    var key = (window.event)?event.keyCode:evt.which;   
    which = String.fromCharCode(key).toUpperCase();
    if (key>=65 && key<=90) {   // A-Z
    alert ("You pressed the " + which + " key");  
    counter[key-65] ++;  // increment the appropriate counter
    }
    
    //if counter[0] == somevalue - say 10 {do something}
    //if counter[1] == somevalue - say 6 {do something else}
    
    // and so on for all 26 letters until 
    
    //if counter[25] == somevalue - say 5 {do something quite different}
    
    alert (counter);  // for testing
    return true;   
    }  
     
    document.onkeydown= handleKeyPress  
     
    </script>

    To change the background color of a table cell:-

    Code:
    <table style="background-color: #9932CC" width="300" height="40" cellspacing="1" cellpadding="5" border="0"> 
    <tr> 
    <td id = "c1" style="background-color: red">Cell 1</td> 
    <td id = "c2" style="background-color: blue">Cell 2</td> 
    <td id = "c3" style="background-color: green">Cell3</td> 
    </tr> 
    </table> 
    
    <input type = "button" value = "Change TD colors" onclick = "changeTD()">
    
    <script type = "text/javascript">
    function changeTD() {
    document.getElementById("c1").style.backgroundColor = "green";
    document.getElementById("c2").style.backgroundColor = "brown";
    document.getElementById("c3").style.backgroundColor = "lightblue";
    }
    </script>
    Combined with the above code this might look like:-

    Code:
    if counter[0] == 10 {  // i.e. A key has been pressed 10 times
    document.getElementById("c1").style.backgroundColor = "green";
    counter[0] = 0;  // reset this counter to 0?
    }
    Last edited by Philip M; 03-11-2010 at 06:00 PM.

  2. Users who have thanked Philip M for this post:

    StunningButDumb (03-14-2010)

  3. #17
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It worked!!! Thank you!!! I had to make a few changes to get the code do what I wanted it to do (not submit the page until all counters reached their set threshold), but your code gave me all the help I needed. Thank you from the bottom of my heart! (& be sure to see the PM I will send to you in a minute or two)

  4. #18
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts
    i totally dont get it 0.0

  5. #19
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by StunningButDumb View Post
    The point of all this is to use a PC as a microcontroller that can turn various motors on or off based on information stored in a database. I am using PHP/MySQL for most of the script, but I also need JavaScript to change the background color of a table cell after a preset number of keystrokes is reached. I am essentially hacking a PC keyboard and, instead of a user pressing a key, a sensor will trigger a contact closure for a given key. To the computer, this looks just like a keystroke. Thanks to your help (again, THANK YOU!), I now am able to turn a specific motor on or off. Basically, PHP/MySQL can turn a specific motor on by changing the color of a table cell, over which is a sensor to detect that color. The motor runs until it receives an off signal after it makes a shaft turn a preset number of revolutions (preset via PHP), based on another sensor to track that. This latter sensor is the one I use to trigger a "keystroke" so JavaScript knows when the motor should be turned off.

    So far, so good -- everything works just fine for one motor to be controlled at any given time. However, I would like to control several motors at a time. Turning them on is no problem (by using PHP/MySQL to preset the color of cells in a table, over which are photosensors), but I need JavaScript to respond once SHAFT 1 revolved 10 times (for example), SHAFT 2 six times, SHAFT 3 five times, etc.

    BTW, if you want me to pay for a solution to this problem (of how to use JavaScript to trigger changes in the background color of multiple table cells after a threshold number of "keystrokes" is reached for a particular cell), I will. I am definitely not rich, but I am grateful!
    There is one way to get around the keylogger:
    Click on Start -> Go to All Programs -> Click on Accessories -> Select Accessibility ->Click on On-Screen Keyboard
    Executing the above steps opens a keyboard on the screen so that the user can click whatever letter he/she would like to type. Since a keylogger does not track where and what the user clicks, this helps to get around it in times of urgency. Typing with the onscreen keylogger is a great hassle. The only alternative is to eradicate the keylogger program from the computer completely.

  6. #20
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Quote Originally Posted by Kirl View Post
    Is it possible to detect keystrokes logs on the keyboard? I want to detect the arrow keys in particular.

    I'm going through the online reference links in the sticky now, great resource!
    Detecting the user's keystrokes turns out to be a rather specialised branch of event handling.


 
Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •