Search code examples
c#consolecontrol-characters

Read Control Characters GS RS


i've to read Barcodes with Control characters like GS (ASCII = dec 29, <F8>), RS (ASCII = 30, <F9>), ... With my first console application, these chars are filtered - I have no idea where and why.

If I scan the Barcode to a redhat-linux-Console the Characters are available:

ü=:<F9>06<F8>1TBUS0000420<F8>P4474453146<F8>Q15<F8>2K14006956<F8>V204930<F8>30S81.031.59.264<F8>3S5500201767<F8>13YY<F9>EOT

But within my console, the chars <F9> <F8> are missing.

My c#-Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{ 
   class Program
   {
      static void Main(string[] args)
      {
        String text = Console.ReadLine();
        Console.WriteLine(text);
        Console.ReadLine();
      }
   }
}

How can I read these chars?


Solution

  • Working example, which Returns all characters:

        static void Main(string[] args)
        {
    
            ConsoleKeyInfo cki;
    
            Console.WriteLine("Press the Escape (Esc) key to quit: \n");
            do
            {
                cki = Console.ReadKey();
                Console.Write(" --- You pressed ");
                Console.WriteLine(cki.Key.ToString());
            } while (cki.Key != ConsoleKey.Escape);
    
        }