Closed Thread
Results 1 to 5 of 5

Thread: sending keystrokes to PHP without reloading

  1. #1
    aloishis89 is offline Newbie
    Join Date
    Aug 2008
    Posts
    12
    Rep Power
    0

    sending keystrokes to PHP without reloading

    I am working on a control panel for a web controlled robot. I'm trying to improve the way that I control it. I'd like to be able to use keystrokes, like WASD, to execute certain functions I've written in PHP (forward, left, back, right). I know I can detect what keys are being pressed using javascript, but I don't know how to pass this information to PHP without having to reload the page. I would also like to be able to implement a failsafe to shut down the robot when it loses the connection. I'm learning Ajax for this project as I go, so I'm pretty new to it. I've done a little research and heard about this thing called COMET that looked like it might be useful. So my questions are, is it possible to send keystrokes detected in javascript to PHP without reloading the page each time a keystroke is sent, and would something like COMET be useful in this situation?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: sending keystrokes to PHP without reloading

    You'll need to use AJAX to send the keystrokes back to PHP.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    aloishis89 is offline Newbie
    Join Date
    Aug 2008
    Posts
    12
    Rep Power
    0

    Re: sending keystrokes to PHP without reloading

    Could you be a little more specific? Maybe a link to an example or something similar?

  5. #4
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: sending keystrokes to PHP without reloading

    You'll need an AJAX request: AJAX Tutorial
    that triggers when the user presses a key: onkeypress Event
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  6. #5
    t3tris is offline Newbie
    Join Date
    Feb 2010
    Posts
    5
    Rep Power
    0

    Re: sending keystrokes to PHP without reloading

    AJAX request looks like this:

    Code:
    var j=new XMLHttpRequest();
    
    var p="wPressed=true&sPressed=false&aPressed=false&dPressed=false";
    
    var url="mypage.php?"+p; //local directory
    
    j.open("GET",url,false);
    
    j.send(null);
    
    document.write(j.responseText);
    for the php code: echo $_GET["wPressed"];

    in this example, the responseText would be whether or not w was pressed. You'll have to implement yourself, but this is the basic concept. You don't need COMET for something like this. Use COMET when you need to be able to update a page in response to something on the server's end. If the chain is called from the client end though, there is no need.
    Last edited by Jaan; 02-28-2010 at 05:20 AM. Reason: Please use code tags when you are posting your codes!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need help with sending packets.
    By Sylfaen in forum General Programming
    Replies: 9
    Last Post: 01-29-2011, 11:46 AM
  2. I need help with sending class
    By AdrianWierciochPHP in forum PHP Development
    Replies: 6
    Last Post: 01-01-2011, 06:55 PM
  3. Sending mail
    By harkoslav in forum C and C++
    Replies: 8
    Last Post: 07-29-2010, 03:26 AM
  4. Sending emails
    By Vswe in forum Visual Basic Tutorials
    Replies: 8
    Last Post: 04-13-2010, 06:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

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