How can I get direct keyboard input in cpp? (cross platform) - c++

I want to be able to control the program with direct input without pauseing the program and without waiting for the user to press enter.
I can currently achieve this with kbhit, but it appears that is a windows only solution.
Ncurses also looks promising, but it appears to only work for linux (and maybe mac? Is unix the structure mac is based on?).
I especially like the kbhit for it's simplicity, and I like the tool set that ncurses, but I was wondering if there was a simple, easy way to get something running cross-platform without having to maintain essentially 2-3 versions of the code using these different tools?

I figured out my problem. I'm trying to do many things that cpp was never intended to do by default, so the options are to use libraries like allegro, or, in my case it turns out what I needed was a game engine. I found that Unity with text mesh pro can do everything I need it to. It comes with an entire input management system.

Related

How to track the number of times my console application in C++14 has been launched?

I'm building a barebones Notepad-styled project (console-based, does not have a GUI as of now) and I'd like to track, display (and later use it in some ways) the number of times the console application has been launched. I don't know if this helps, but I'm building my console application on Windows 10, but I'd like it to run on Windows 7+ as well as on Linux distros such as Ubuntu and the like.
I prefer not storing the details in a file and then subsequently reading from it to maintain count. Please suggest a way or any other resource that details how to do this.
I'd put a strikethrough on my quote above, but SO doesn't have it apparently.
Note that this is my first time building such a project so I may not be familiar with advanced stuff... So, when you're answering please try to explain as is required for a not-so-experienced software developer.
Thanks & Have a great one!
Edit: It seems that the general advice is to use text files to protect portability and to account for the fact that if down-the-line, I need to store some extra info, the text file will come in super handy. In light of this, I'll focus my efforts on the text file.
Thanks to all for keeping my efforts from de-railing!
I prefer not storing the details in a file
In the comments, you wrote that the reason is security and you consider using a file as "over-kill" in this case.
Security can be solved easily - just encrypt the file. You can use a library like this to get it done.
In addition, since you are writing and reading to/from the file only once each time the application is opened/closed, and the file should take only small number of bytes to store such data, I think it's the right, portable solution.
If you still don't want to use a file, you can use windows registry to store the data, but this solution is not portable

Netbeans - copy highlighted regex search results

I made a simple regex search in Netbeans 7.3 on Windows (using Ctrl+F):
\{\{.*?\}\}
The results get highlighted correctly and the question is - how to extract highlighted text search results? Let it be copying to clipboard, saving as file or whatever else.
Is there any method doing this?
Maybe someone has any suggestion of alternative quick approach to such task in Netbeans? (or other editor)
What OS are you running? If OS X or Linux, read on!
I'm not sure about automatically copying the highlighted results to the clipboard, but I do workaround this quite a bit as well.
The easiest way to accomplish this for me without leaving NetBeans is to simply open a built in terminal window through Window>Output>Terminal (in 7.2.1) - I then navigate to my project, and run the RegEx that I built in the Find feature with my tool of choice. In fact, I use the built in terminal for this type of quick stuff in NetBeans quite a bit. If running Linux, using clipboard tools like xsel (http://linux.die.net/man/1/xsel) in combination with a built in terminal emulator can allow for devising some nice workflow shortcuts within IDEs if you are more comfortable working/coding at a terminal. Note that built in terminal emulators like the one in NetBeans is likely not going to play nicely with cut/copy/paste using the mouse, for various reasons that I won't get in to here.
As far as a built in/extension based solution for something like this, it would be helpful! I am not aware of one.
Hope this workaround helps in the meantime.

Find what was printed in the terminal

Is there anyway to check the terminal (Linux, and Windows) for characters at certain positions? I have external methods loaded via an explicitly loaded dll that prints certain characters onto the screen. I need to see if the functions printed what they were supposed to with minimal cross talk between the between the plugins. So at the core I am wondering if C++ has any feature for pulling chars off of the termial/command line?
This is not possible on VT100-like terminals (the kind popular in Linux.)
For Windows I can't say, but if you are using a cygwin terminal (not the power shell or the "DOS shell") the answer is again no.
You could use tmux or screen to set up a virtual terminal. The display state can then be captured, which seems to be what you want. But something in my brain is telling me that, whatever you are trying to do, this is probably not the right solution. What exactly is your problem?

Pseudographical environment in windows Command Prompt

actually i'm thinking of creating a cool interface for my programming assignment , so i go around searching on how to do it so that such an effect can be create , below is the image .
The Question
1.)What is needed in order to create a program that run pseudographic(semigraphic or whatever they called it) that has menu like BIOS wizard did??I always see some program run in console but it could have graphical-like looking , for example blue environment , and user can use keyboard to choose a list of setting in a menu.
Thanks for spending time reading my question.
It's called Text-based user interface. There're several libraries for doing this. I think this is what you're looking for. :)
Cross platform, Interactive text-based interface with command completion
http://www.gnu.org/s/ncurses/
Ncurses(or maybe pdcurses) is probably what you need.
In the days of 16-bit Windows console windows used to support ANSI escape sequences (via the ansi.sys driver), but they no longer do.
For the apparent line graphics you need to use a platform specific solution anyway, so I recommend just writing an abstraction (functions, class) over the Windows APIs console functions.
The line graphics is done by using characters from the original IBM PC character set, codepage 437. At first you can just hardcode the various patterns. In order to make it seem more like line drawing to the code, or from the code's perspective, so to speak, you'll have to abstract things again. As I remember there is some partial but not complete system in the original codepage 437 character codes. But for Windows console you will need to use the Unicode character codes, which probably do not preserve the original system, so perhaps just define a map where these graphics characters are placed more systematically.
Possibly that already exists.
If you don't care about portability, the Windows API for this can be found here. It will supply all the functions you need, without the need to pack additional libraries with your application.
You can also look in to graphics.h, a non-standard Borland extension that a lot of older graphical games used to use. It goes far beyond the normal limits of the console, but is only supported by 16 bit systems, of which Microsoft has all but removed support for from Windows. You'd also need an ancient Borland compiler, or an emulation, though you probably want the original look and feel.

How can I develop a virtual drive

I would like to create a virtual drive for windows. I'm not looking to map a drive or something like that, I'm looking to map it to my DLL functions or something of that sort.
How can I get this accomplished?
I read that I would have to develop a device driver, or a shell extension?
I have a lot of experience with C++ and C#. Where do I get started?
I want to make it as simple as possible at first, how much time do I think it would take me? And what's the simplest way to do it, so that I could build my prototype.
My motivation is to pipe a file into an application, that currently only reads files from the file system. I'm only interested in pumping 1 file, so I think that a whole virtual drive would be an overkill, as well as writing kernel mode code.
If you want to build it from scratch then yes, you have to build a driver. However, it would be much easier for you to use a proxy driver like Dokan, and create the file system in user mode.
Take a look at the Wikipedia article on IFS, there are links to other useful tools at the bottom of the page.
I don't know what it worth, and it's not open source, but I've found this. It's a "fuse" like for windows