.net – How can I read from STDIN in a WPF application – Education Career Blog

The question is that I have some HID devices that act as a keyboard (MSR, Barcode scaner, RFID reader) and I want to be able to read their input in my WPF application without the necessity for this to happen in say a text field in the application.

Is it possible to read from STDIN in a WPF application.

calling Console.ReadLine() returns null every time.

,

You will need a console. Two routes:

  1. Make the application type a Console application (console applications can have windows as well). This will ensure a console is created by Windows on startup (or it will run inside the parent’s console if the parent has one).

  2. Use P/Invoke to call AllocConsole. This has the advantage of your application (1) never inheriting a parent processes’ console, and (2) application logic can determine if and when it is created.

Leave a Comment