Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send Escape Key as Extended Ascii

Status
Not open for further replies.

nbaker76

Programmer
May 7, 2005
11
US
Does anyone out there know how I can simulate sending an Escape key press and append it to a string that I am writing to an open port.

private Rs232 myPort = new Rs232();

try
{
// open the port
myPort.Open(1, 9600, 8, Rs232.DataParity.Parity_None, Rs232.DataStopBit.StopBit_1, 4096);
myPort.Write(Encoding.ASCII.GetBytes("?TEST1ON"));
myPort.Write(Encoding.ASCII.GetBytes("?TEST1OFF"));
myPort.Close();

}

The arrow pointing left is what I get when I press Alt 27 the decimal equivalent of the Escape key. It doesn't seem to be working...I need to send Escape then the string TEST1ON. Does anyone know what I can use to send an Escape keystroke as ascii?

Thank you
 
In VB.Net you could use:

Dim EscapeChar as string
Dim Test1On as String
Dim Test1Off as String

EscapeChar = Chr(27)
Test1On = EscapeChar + "TEST1ON"
Test1Off = EscapeChar + "TEST1OFF"

I think the equivalent for EacapeChar in C# would be something like:

EscapeChar = (char) 27

Since C# is not my language of choice, I'll leave you to work out the rest.

Hope this helps.
 
Hi,

Thanks for the tip, but I have actually tried to implement this since my last post...in C# it is this.

char esc = (char)27;

but when i try to do a myPort.Write(esc) it seems as if the command isn't getting sent.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top