import processing.net.*; import java.awt.AWTException; import java.awt.Robot; import java.awt.event.InputEvent; Robot robot; String HTTP_GET_REQUEST = "GET /"; String HTTP_HEADER = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"; Server s; Client c; String input; char keycode; void setup() { s = new Server(this, 8080); // start server on http-alt try { robot = new Robot(); } catch (AWTException e) { e.printStackTrace(); } } void draw() { // c = s.available(); if (c != null) { input = c.readString(); input = input.substring(0, input.indexOf("\n")); // if (input.indexOf(HTTP_GET_REQUEST) == 0) { c.write(HTTP_HEADER); input = input.substring(4,7); // if(input.indexOf('q') > 0) keycode=KeyEvent.VK_Q; if(input.indexOf('w') > 0) keycode=KeyEvent.VK_W; if(input.indexOf('e') > 0) keycode=KeyEvent.VK_E; // robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(keycode); // robot.keyRelease(keycode); robot.keyRelease(KeyEvent.VK_SHIFT); c.stop(); // } } }
<?PHP header("Content-Type: text/html; charset=windows-1251"); $act = $_REQUEST['act']; if(!$act) buttons(); // if($act=='push') push(); // function push(){ $btn = $_REQUEST['btn']; if($btn!='') { // $fp = fopen("http://___:8080/".$btn, "r"); fclose($fp); } } function buttons() { // JavaScript ?> <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html><head> <script type="text/javascript"> function getXmlHttp(){ var xmlhttp; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); } return xmlhttp; } function btnClick(i) { //alert(i); var req = getXmlHttp(); req.open('GET', 'index.php?act=push&btn='+i, true); req.send(null); } </script> <button style="width: 100%; height: 50px;" onclick='btnClick("q")'></button><br><br> <button style="width: 100%; height: 50px;" onclick='btnClick("w")'>2 </button><br><br> <button style="width: 100%; height: 50px;" onclick='btnClick("e")'></button><br><br> </head></html> <?PHP } ?>
Source: https://habr.com/ru/post/196990/
All Articles