The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

3 Pages V < 1 2 3  
Reply to this topicStart new topic
> How to run .py in html
CharlesEF
post Mar 22 2016, 03:49 PM
Post #41


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Ok, give me a few days. I need to catch up on a few things and I need to think about your requirements.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Kristijan1392
post Mar 22 2016, 05:02 PM
Post #42


Member
***

Group: Members
Posts: 32
Joined: 10-November 15
Member No.: 23,730



thank you for effort and everything
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 25 2016, 05:38 AM
Post #43


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Ok, I think this takes care of all your requirements. If you hold 2 keys down, say left-right, then you release the left key then the right command will be executed. If you then press the up key then the right-up command will be executed. There is 1 gotcha with this code, you can't repeat the same command one after the other. If you press and hold the up key then release it the stop will run. Now you can't press the up key again, at least until you press another key first. If you press and hold the up-left keys and then you release the left key then you can't press the left key again, until you press a different key first. This is a side effect of the code I used to trap multiple keystrokes (and filling up the keyboard buffer). Be sure to change the commands, if needed.

control.php
CODE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Control Module</title>
<script type="text/javascript">
var key_seq = null, cur_key = null, pre_key = null, pre_seq = null;

document.onkeydown = function(event)
{
if(event.which != pre_key)
{
  key_seq.value += 'd' + event.which;
  cur_key.value = 'd' + event.which;
  pre_key = event.which;
}
setTimeout("controlIt(key_seq.value)", 500);
}

document.onkeyup = function(event)
{
key_seq.value = key_seq.value.replace('d' + event.which, '');
cur_key.value = 'u' + event.which;
setTimeout("controlIt(key_seq.value)", 500);
}

function controlIt(key_sequence)
{
var cont = true;

if(pre_seq == key_sequence)
{
  return(false);
}
switch(key_sequence)
{
  case "d38d37": // Up-Left arrow keys - key down
   action = 'UpLeft';
   break;
  case "d38d40": // Up-Down arrow keys - key down
   action = 'UpDown';
   break;
  case "d38d39": // Up-Right arrow keys - key down
   action = 'UpRight';
   break;
  case "d37d38": // Left-Up arrow keys - key down
   action = 'LeftUp';
   break;
  case "d37d40": // Left-Down arrow keys - key down
   action = 'LeftDown';
   break;
  case "d37d39": // Left-Right arrow keys - key down
   action = 'LeftRight';
   break;
  case "d40d38": // Down-Up arrow keys - key down
   action = 'DownUp';
   break;
  case "d40d37": // Down-Left arrow keys - key down
   action = 'DownLeft';
   break;
  case "d40d39": // Down-Right arrow keys - key down
   action = 'DownRight';
   break;
  case "d39d38": // Right-Up arrow keys - key down
   action = 'RightUp';
   break;
  case "d39d40": // Right-Down arrow keys - key down
   action = 'RightDown';
   break;
  case "d39d37": // Right-Left arrow keys - key down
   action = 'RightLeft';
   break;
  case "d87": // W Key - key down
  case "d38": // Up arrow key - key down
   action = 'Up';
   break;
  case "d65": // A key - key down
  case "d40": // Down arrow key - key down
   action = 'Down';
   break;
  case "d37": // Left arrow key - key down
   action = 'Left';
   break;
  case "d39": // Right arrow key - key down
   action = 'Right';
   break;
  case "": // Empty key_sequence value - key up
   action = 'Stop';
   break;
  default:
   cont = false;
   break;
}
pre_seq = key_sequence;
if(cont)
{
  var formData = new FormData();
  formData.append("moveit", action);
  var xhr = new XMLHttpRequest();
  xhr.open("POST", "controlit.php", true);
  xhr.send(formData);
}
}
</script>
</head>
<body>
<input type="hidden" id="key_seq" title="Key Sequence" value="">
<input type="hidden" id="cur_key" title="Current Key" value=""><br>
<input type="button" name="up" title="Click to move up." value="Up" onmousedown="controlIt('d38');" onmouseup="controlit('');">
<input type="button" name="down" title="Click to move down." value="Down" onmousedown="controlIt('d40');" onmouseup="controlit('');">
<input type="button" name="left" title="Click to move left." value="Left" onmousedown="controlIt('d37');" onmouseup="controlit('');">
<input type="button" name="right" title="Click to move right." value="Right" onmousedown="controlIt('d39');" onmouseup="controlit('');"><br>
<script type="text/javascript">
window.onload=function()
{
key_seq = document.getElementById('key_seq');
cur_key = document.getElementById('cur_key');
}
</script>
</body>
</html>

controlit.php
CODE
<?php
if(isset($_POST['moveit']))
{
switch($_POST['moveit'])
{
  case 'UpLeft':
   exec("sudo python /home/pi/upleft.py");
   break;
  case 'UpDown':
   exec("sudo python /home/pi/updown.py");
   break;
  case 'UpRight':
   exec("sudo python /home/pi/upright.py");
   break;
  case 'LeftUp':
   exec("sudo python /home/pi/leftup.py");
   break;
  case 'LeftDown':
   exec("sudo python /home/pi/leftdown.py");
   break;
  case 'LeftRight':
   exec("sudo python /home/pi/leftright.py");
   break;
  case 'DownUp':
   exec("sudo python /home/pi/downup.py");
   break;
  case 'DownLeft':
   exec("sudo python /home/pi/downleft.py");
   break;
  case 'DownRight':
   exec("sudo python /home/pi/downright.py");
   break;
  case 'RightUp':
   exec("sudo python /home/pi/rightup.py");
   break;
  case 'RightDown':
   exec("sudo python /home/pi/rightdown.py");
   break;
  case 'RightLeft':
   exec("sudo python /home/pi/rightleft.py");
   break;
  case 'Up':
   exec("sudo python /home/pi/up.py");
   break;
  case 'Down':
   exec("sudo python /home/pi/down.py");
   break;
  case 'Left':
   exec("sudo python /home/pi/left.py");
   break;
  case 'Right':
   exec("sudo python /home/pi/right.py");
   break;
  case 'Stop':
   exec("sudo python /home/pi/stop.py");
   break;
}
}
?>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 26 2016, 07:48 AM
Post #44


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Seems I forgot to change the function name for the 4 onmouseup button events. Swap the 4 buttons code with this:
CODE
<input type="button" name="up" title="Click to move up." value="Up" onmousedown="controlIt('d38');" onmouseup="controlIt('');">
<input type="button" name="down" title="Click to move down." value="Down" onmousedown="controlIt('d40');" onmouseup="controlIt('');">
<input type="button" name="left" title="Click to move left." value="Left" onmousedown="controlIt('d37');" onmouseup="controlIt('');">
<input type="button" name="right" title="Click to move right." value="Right" onmousedown="controlIt('d39');" onmouseup="controlIt('');"><br>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Kristijan1392
post Mar 26 2016, 11:30 AM
Post #45


Member
***

Group: Members
Posts: 32
Joined: 10-November 15
Member No.: 23,730



Thank you a loot,I will try this in a few days,and let you know how it works,i will send you a link so you can try it by your self smile.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 26 2016, 04:38 PM
Post #46


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Here is another version that includes buttons. The buttons with 2 directions (like 'Up-Down') requires both the left and right mouse buttons to be pressed and held. Be sure to press the left mouse button before the right button in order to get the 'Up-Down' movement. If you press the right mouse button before the left then you will get 'Down-Up' movement. Let's say you press the left mouse button and then the right (for 'Up-Down'). Now, if you release the right mouse button then the 'Up' command will run. When you release the left mouse button the 'Stop' command will run. Let's say you still have both buttons pressed and held. If you release the left mouse button then the 'Down' command will run. When you release the right button the 'Stop' command will run. Also, let's say you still have both left and right buttons pressed and held (for 'Up-Down'). If you release the right mouse button then the 'Up' command will run. If you press and hold the right mouse button again then the 'Up-Down' command will run again. In other words, the buttons don't have the same problem as the arrow keys (you can repeat the same key sequence).
Attached File  control1.php ( 6.14k ) Number of downloads: 543


This post has been edited by CharlesEF: Mar 26 2016, 04:57 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 26 2016, 09:42 PM
Post #47


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Here is a corrected version. I forgot to change the functions for the first 4 buttons and they didn't work. Now they do.
Attached File  control1.php ( 6.23k ) Number of downloads: 569
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Kristijan1392
post Mar 27 2016, 11:29 AM
Post #48


Member
***

Group: Members
Posts: 32
Joined: 10-November 15
Member No.: 23,730



thank you very much,i still need to find appropriate wheels and then i will send you my domain in inbox so you can try hoe it works,thank you for everything
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 27 2016, 11:48 AM
Post #49


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



I fixed the repeat command problem and I removed some code I was using during testing. I also made the W,S,A and D keys to act like arrow keys. W=UP, S=DOWN, A=LEFT and D=Right.
Attached File  control1.php ( 6.69k ) Number of downloads: 574
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Mar 28 2016, 06:01 PM
Post #50


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



I should mention that if you want to limit the browser used to IE only then you could use Active-X to run the commands directly. No need for a web server
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

3 Pages V < 1 2 3
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 25th April 2024 - 01:57 AM