How to output keystrokes to my computer
Does anyone know how to output keystroke characters to my desktop computer with a BS2?· For example, when· I press a button on my BS2 project board, I would like to see a character show up on Notepad or Wordpad (or any other program for that matter).·· I have a USB2SER adapter on my BS2.··
I am building a flight simulator, and MS Flight Simulator will allow for keypress assignments within the program.· I would like to avoid adding extra cabling to my BS2 project board, like a PS2.· The idea solution would output the text through the USB cable that is all ready connected to the computer.·· Can this program code reside completely in the BS2, and not have to run external software loaded my desktop computer?
Thanks for your help.
I am building a flight simulator, and MS Flight Simulator will allow for keypress assignments within the program.· I would like to avoid adding extra cabling to my BS2 project board, like a PS2.· The idea solution would output the text through the USB cable that is all ready connected to the computer.·· Can this program code reside completely in the BS2, and not have to run external software loaded my desktop computer?
Thanks for your help.

Comments
SlashWeep's method is the only way you are going to get it to work with just the USB. In C# and VB.NET, you have a function called "Sendkeys" that will take whatever key you feed it and send it to the open application. I don't think there's too much danger of missing the key press as long as the C# program is listening for the character in a loop. It would look something like this (pseudocode):
serial_port = Serial.open("com3"); // or com1, or 2, or 4...
while (running)
{
key_pressed = serial_port.receive();
SendKeys(key_pressed);
}
Have a great day!
[color=#0000ff]using[/color][color=#000000] System;[/color] [color=#0000ff]using[/color][color=#000000] System.Collections.Generic;[/color] [color=#0000ff]using[/color][color=#000000] System.ComponentModel;[/color] [color=#0000ff]using[/color][color=#000000] System.Data;[/color] [color=#0000ff]using[/color][color=#000000] System.Drawing;[/color] [color=#0000ff]using[/color][color=#000000] System.Text;[/color] [color=#0000ff]using[/color][color=#000000] System.Windows.Forms;[/color] [color=#008000]//Need to access the port [/color][color=#0000ff]using[/color][color=#000000] System.IO.Ports;[/color] [color=#0000ff]namespace[/color][color=#000000] COMBS2Test[/color] { [color=#0000ff]public[/color] [color=#0000ff]partial[/color] [color=#0000ff]class[/color] [color=#008080]frmMain[/color] : [color=#008080]Form [/color]{ [color=#0000ff]public[/color] frmMain() { InitializeComponent(); } [color=#008000]//Make sure you add a textbox called txtDebug to frmMain [/color][color=#008000]//Create a serial port [/color][color=#008080]SerialPort[/color] sPort = [color=#0000ff]new[/color] [color=#008080]SerialPort[/color](); [color=#0000ff]private[/color] [color=#0000ff]void[/color] frmMain_Load([color=#0000ff]object[/color] sender, [color=#008080]EventArgs[/color] e) { [color=#008000]//Change this to match your com port name [/color]sPort.PortName = [color=#800000]"COM4"[/color]; [color=#008000]//Add an event for DataReceived [/color]sPort.DataReceived += [color=#0000ff]new[/color] [color=#008080]SerialDataReceivedEventHandler[/color](sPort_DataReceived); [color=#008000]//Open the port, not sPort.Close() will close it [/color][color=#008000]//Note you can not run the Basic Stamp Editor Debugger at the same time [/color]sPort.Open(); }[color=#008000]//end function [/color][color=#008000]//When the event fires this function is called on a new thread [/color][color=#0000ff]private[/color] [color=#0000ff]void[/color] sPort_DataReceived([color=#0000ff]object[/color] sender, [color=#008080]SerialDataReceivedEventArgs[/color] e) { [color=#008000]//We need to call a Delegate to be thread safe [/color][color=#0000ff]this[/color].PostData(sPort.ReadExisting()); }[color=#008000]//end function [/color][color=#008000]//Delegate type function [/color][color=#0000ff]private[/color] [color=#0000ff]void[/color] PostData([color=#0000ff]string[/color] Data) { [color=#008000]//Check to see if we are on the "Main" thread and not a spawned thread (event fire) [/color][color=#0000ff]if[/color] ([color=#0000ff]this[/color].InvokeRequired) { [color=#008000]//This is a short simple line that creates a new delegate that points to our self and then invokes it onto the main thread [/color][color=#0000ff]this[/color].EndInvoke([color=#0000ff]this[/color].BeginInvoke([color=#0000ff]new[/color] [color=#008080]MethodInvoker[/color]([color=#0000ff]delegate[/color]() { PostData(Data); }))); } [color=#0000ff]else [/color]{ [color=#008000]//This was called by the main thread so, now we can append the data to the text box [/color]txtDebug.Text += Data; }[color=#008000]//End if [/color]}[color=#008000]//End function [/color]}[color=#008000]//end class [/color]}[color=#008000]//end namespace [/color]·
I attached it to this thread a long while back .. Should do the trick
http://forums.parallax.com/showthread.php?p=627711
it is listed as Par_kb.zip
I have attached a link to it here also..
http://forums.parallax.com/attachment.php?attachmentid=45863
John Twomey
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Necessity is the mother of invention'
Thanks for the code and your suggestions.· I have not had a chance to try out the program yet, but I'll let you know if I have problems.