Is there a way to use getChar() in console and not have it include the tabs? - c++

I'm trying to use getchar() to read characters one at a time from a windows console. However, when I hit tab it visually inserts the spacing of a tab in the console, rather than just registering to stdin as \t.
I want to hit tab in the console and not have anything change visually in a console, I want be able to have my code interpret tabs separately.
Is there any way to do this?
I know _getch() does this, it doesn't insert a tab in the console, but I can't use that function because I need signals to be able to be sent.

No, that's not possible because it's unrelated to your program and your code. Most terminals are line buffered (and so are Windows terminal and PowerShell). The terminal will send the input to your program after you pressed enter. Before you press enter your program won't know about any input. You need conio.h with getch or something similar. You can't achieve this behavior with standard library only.

Related

How to prevent enter key on windows console from automatically scrolling

Whenever I type some characters into the windows console and hit enter, it automatically scrolls to the next line. Is there any way to disable this behavior in C++ (using the Windows API), and if so; how?
If you call scanf or getline or similar then the underlying C runtime (CRT) handles Enter, Backspace, Delete, arrow keys, Tab, and such, and of course all printable keys.
If you want to handle Enter differently from CRT then you will have to handle every other key as well, using _getch (nonstandard function different from getchar). You will have to write some code. As far as I know there is no way to use scanf or getline, without Enter going to the next line.

Most suitable way to read keyboard input in C++

I'm trying to write a Keyboard class that can read in the keyboard buttons. I have looked at this link - http://www.daniweb.com/software-development/cpp/code/216732/reading-scan-codes-from-the-keyboard But as stated on there, it is not very accurate for all computers (I don't know if this is even true). Therefore, my question is whats the best method in implementing my keyboard class? This will be used for Windows
Many thanks
There are three ways to read keyboard input:
By reading input from a console window as described in your link. It's true that it's hard to get this to work correctly, for starters because it's reading ANSI characters and not Unicode characters, but there are other issues. Console input/output is kind of obscure, as is the documentation for it
By handling UI events associated with a normal window. In this case you would handle the WM_KEYDOWN message in a window procedure
By going deep into the Win32 API with functions like SetWindowsHookEx. In this case you don't even need a window (normal or console), and you can read keystrokes pressed in any application or in the desktop
It's hard to suggest which one to use without knowing how you intend to use this Keyboard class.

If loop that executes when Enter key is pressed C++

I'm using Windows XP Home Edition. I want to set up a menu system that displays an image when the Enter key is pressed. Is there any way I can set up an if statement that executes when the Enter key is pressed on the keyboard without setting up a GUI. For example, can I just use the hex value associated with Enter key as a trigger for the if statement.
I've looked into reading input buffers. Am I going to have to get that complex with it? I don't really
For windows there are a couple of variants you could use to implement this:
The standard way would be to call e.g. std::getline and discard the input.
A more Windows-specific solution is to use e.g. _kbhit and _getch to check for the Enter key.

Symbian simulate keyboard input

I have created a Qt background task that generates text on account of user input. My task runs when a text input field is open, what I now need is a way to insert text into the input of whatever application is currently open. I have looked at key press simulation but I cannot find a method that works.
Do you gave any idea what I can do?
PS. This is for Symbian^3(Belle) and Qt as well as Symbian C++ code will work.
On way to do it is
RWsSession sess=CCoeEnv::Static()->WsSession();
sess.SimulateKeyEvent(RFB::GetKeyEvent(code,ETrue));
User::After(200000);
sess.Flush();

want to open text file in some text editor programmatically in c/c++

I want to open a text file into some text editor say notepad programmatically in c/c++.
Also i want to see real time updation of text into that text file while opening in a editor.
Please suggest.
Most editors accepts the path of the file-to-be-opened as 1st argument. E.g.
notepad.exe c:/foo.txt
Just execute it as a shell/runtime command in your program.
If you're doing something as simple as monitoring a log file, you want a unix program called "tail", or its Windows equivalent.
It will give you a simple Notepad-like Window which displays the contents of a log file in (more or less) real time.
Having the editor (notepad, tail, whatever) continually monitor the file for changes isn't your job as the C++ developer, it's up to the program.
To get the file to open in the default application specified, try this (C#):
System.Diagnostics.Process.Start("text.txt");
To specify an application, try this:
System.Diagnostics.Process.Start( "notepad.exe", "text.txt");
I'm not aware of any way to handle real time updation of the file in the editor however.
After you have it running, see above. you can possibly keep the file updated using SendMessage from the Windows API and sending Ctrl+S(save) to the notepad window.
To see real time update in your editor window try to find editor's window handle (you may use EnumWindows() function). Insert text in the editor's textfield or reread it from the file and call RedrawWindow() after that. However calling it after each letter could give some nasty flickering if the text come from a program.