loading
 
VBScript to Keyboard Send
Anonymous
13 year
I am trying to make a usb missile launcher follow a red blob and then shoot it when it centers on it. (see attached) I am using the Keyboard_Send module to send a left or a right keyboard arrow to the missile launcher program.

The only part that does not work is reassigning a different value to the "key_ to_send" variable each time I move the blob.   For instance when I move the blob to the left and test <=100, "key_to_send" is still shows up as equal to {RIGHT} (under the modified Variable table in VBScript module) instead of {LEFT}. So the missile launcher continues to turn right.

Let me know if you have any advice.



Here is the VBScript I am using( I have attached the .robo file I am using):


cogx = GetVariable("COG_X")
leftThreshold = 100
rightThreshold = 200

SetVariable "test", cogx

if test <= leftThreshold then
  SetVariable "key_to_send", "{LEFT}"
else
  if test >= rightThreshold then
  SetVariable "key_to_send", "{RIGHT}"
  else
    SetVariable "key_to_send", ""
  end if
end if

 

program.robo
Anonymous 13 year
Your "test" VBScript variable is not actually set ... you save it using a SetVariable but you should instead use cogx in the actual VBScript comparisons. Using the Subroutine SetVariable does NOT automatically create a variable in VBScript with that same value. So replace test with cogx.

Attached is your corrected robofile.

Also, we have a module for the USB missile launch which may be more reliable than the keyboard_send ...

http://www.roborealm.com/help/DC_Missile.php

Thanks for the pic!

STeven.
program.robo
Ben from United States  [4 posts] 13 year
That's great! Thanks for the help.
Ben from United States  [4 posts] 13 year
Do you know how to send "SPACEBAR" through the keyboard send program?


Hitting space bar is how I shoot the nerf gun.


Ben
www.focus4tech.com
Anonymous 13 year
Ben,

Does just typing a space not work? Seems to send it to notepad just fine.

What leads you to believe that just typing a space does not work?

STeven.
dope40 from Bulgaria  [1 posts] 12 year
cogx = GetVariable("COG_X")
xcor = 350
ycor = 300
test=cogx

if test <= ycor  then
  SetVariable "key_to_send", "{RIGHT}"
else
  if test >= xcor then
  SetVariable "key_to_send", "{LEFT}"
  else
    SetVariable "key_to_send", ""
  end if
end if

That's how i did it and it work . :d

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index