Read input live from the terminal C++ - c++

I want something with C++ that can read what I type in the terminal and assign it to a string variable.
I want this for a project to make something like notepad, but in simple terminal form, so I need to have live user input available to get word count and stuff.
Unfortunately, I couldn't find anything on the internet about this, and I only found sites that talked about keyboard input, but I don't want that.
I tried to test this using the getch() function and there was no problem in writing and getting input.
But when the user wants to delete something, we don't know which character the user deleted, because we don't have the selected character, if we have it, when we print it after getting the character (if we don't print the user he just writes and doesn't know what he wrote) the problem is that the page must be cleaned once after deleting a letter and this causes the terminal to tick

Related

How to write tab command in c++ to switch input form

I have a database and I want to add that data to a web application using ditto. I copied the data from my domain for me to paste in someone else's domain. With a semicolon separator.
So, I want when the text is pasted, the semicolon changes to the tab command to the next input form. Please help.
Description is in the image in the attachment. Thank you.
DITTO SCRIPT
INPUT FORM
You could try using a vector as a buffer if you're working with ascii characters. just do the same comparisons with a for each loop.

How to set keyboard key using registry

Im looking for a way to write a script (hopefully in python) that remmap specific keyboard keys using the registry.
For example: switching only between the enter and the space bar.
In addition I would like to know if there is away to set the value of the spacebar key.
for example: making the spacebar write the word "space".
Thanks (:
You can use the open source project called Sharp keys to change keys in your registry. Its written in C#, but you may give it a try.
Link: http://sharpkeys.codeplex.com/
While the question is old, the problem is still relevant. I'd suggest using AutoHotkey. Following would trigger Space key when Enter is pressed and would print "space" when space key is pressed:
Enter::
Send, {Space}
return
Space::
Send, space
return

Creating users for game(reading and parsing CSV file)

So I am working on a planets vs zombies type mock up game for class, and am using Qt Creator GUI with C++. One of the things that we are required to do is, on start-up, the game window will attempt to read two files: "pvz_levels.csv" and "pvz_players.csv" from a pre-specified home directory.
The levels file is of the form "level:sequence:rows:start:interval:decrement" and "sequence" itself is a comma separated list of the form (1,1,1,2,3,1,3,1,3,3) which is the sequence in which zombies appear. If this file does not exist in the directory, the program exits with an error.
The players file is of the form "timestamp:player:level"; the time of last play, name of player, and last attempted level, respectively. If this file does not exist, the program silently skips this operation and starts as a new player. If it does exist, the file must be read and parsed, and then used in the program for calculations and such.
So, I am having much trouble with reading and parsing these files. Furthermore, we are required to save the user data in these files, and on the next start-up the user should have the option to continue their game by selecting their respective user from a drop-down list. They should also be able to delete any users.
I am proficient enough with c++ basics but this is my first GUI experience and my prof did not go over it in much detail, so I require quite a bit of help with this project.
Thank you to anyone who is able to help!
Look up the code to an available "csv parser" which stands for "comma separated variable". You need is almost identical, except you use a semi-colon instead of a comma. It seems that by changing one character you parsing is done for you.
You may be able to find a csv parser that accepts the character to be used as the parsing character (I've seen them before).
If you wish I can find a suitable csv parser for your use, but now that you know what you're looking for "csv parser c++ code" it should be a quick Google away.
Also, most csv parsers expect strings to be enclosed to double quotes (") but that is easily modifable.
Some hints:
Just open the File using QFile. Set up a QTextStream and use QTextStream::readLine() to read all Lines into QStringList. Now use QString::split() on the QString saved in the list to get the single values stored in this line. From there you can easily use QString::to* functions to cast the values into your desired type.
For saving just reverse the procedure.
Set up a line using: QString("%1,%2,%3").arg(timestamp).arg(player).arg(level) and put it into your QTextStream. If the stream is connected to a file, this will be written into the file.
I've implemented successfully the CSV reading like this:
std::unique_ptr<QFile> csv_worker(new QFile(resource_path));
QTextStream input_csv(csv_worker.get());
QList<QStringList> data
while(!input_csv.atEnd())
{
//removes the carriage return symbol and splits the elements
QStringList line = input_csv.readLine().remove(QRegExp("\r")).split(","); //replace here with :
data << line;
}
csv_worker->close();
It reads the complete file, each line generates a QStringList.
For the second element in the QStringList, let's say (1,1,1,2,3,1,3,1,3,3}, you have to additionally split that in a sub-QStringList, removing then brackets with something like this:
QStringList sequence = data[i][1].remove(QRegExp("{")).remove(QRegExp("}")).split(",");

Auto-filling Word documents with Access VBA: Normal.dotm template issues

A somewhat similar question has been asked before, but the solution didn't work for me.
For instance, http://www.xtremevbtalk.com/showthread.php?t=99503
Background:
I have a MS Access 2010 database. In my database I have a form with a button. I've programmed the button to open a saved word document, populated book-marked places in the document, then save-as the word document with a name that includes the time (henceforth referred to as the auto-filled document). This all works just fine.
The problem:
If a different MS word document was already open when I clicked the button, then I have trouble closing the resulting auto-filled document. This is what happens:
1) I try to "x" out of my auto-filled word document.
2) the computer tells me that "This file is in use by another application or user // (C:....\Normal.dotm)"
3) I click "ok"
4) it offers to save-as the Normal template.
5) I click "cancel"
6) I try to "x" out of the word application once more.
7) the computer prompts me: "Changes have been made that affect the global template, Normal. Do you want to save those changes?"
8) I click "Don't save"
9) the application closes.
(This only occurs for instances when a word document is already open when I click the button on the form. Otherwise it works perfectly.)
My question:
Normally, I would just shrug and live with these extra few steps, but I'm the one making the database, so I have to think about my users. (Would it mess anything up to save the normal template--step 7?)
I googled this for a while. For similar situations, some people suggested adding objApp.NormalTemplate.Saved = True (where objApp is the Word application object), but this did not work for me.
Can someone please tell me what's going on? Is there a solution?
Any help will be much appreciated.
What you need to do is check to see if an instance of Word is already open. If it is, you might want to let your user know they need to close their Word doc.
' Handle Error In-Line
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
'If we got an error, that means there was no Word Instance
Set objWord = CreateObject("Word.Application")
Else
Msgbox ("You're going to need to close any open Word docs before you can perform this function.", vbOK)
Exit Sub
End If
'Reset Error Handler
On Error GoTo 0

Winapi: edit control not expanding its buffer

According to MSDN:
When the system creates an edit control, it automatically creates a text buffer, sets its initial size, and increases the size as necessary.
Yeah, only it doesn't. I have an edit control in my app that shows various logs, and I keep adding text to it using EM_SETSEL message (to find the end of the text in control's buffer) and EM_REPLACESEL message (to append some text to it). I don't know if it's a best way, but it's been working well so far. Today, however, I found out that if I try to append some text when there are lots of logs in edit control already, my app fails to do so. Maximum lenght of text that's shown in it is equal to 30k characters and when I try to append any more logs, it just fails, nothing happens. At first I set it as read-ony edit control, but nothing changes if I make it editable. Just when I try to type more than 30k characters in it, it acts as if I wasn't typing anything.
And now: I know that you can handle buffer expanding by yourself, but that's not the case here. If it is written that it should be expanded automatically, why doesn't it occur? Maybe I accidentaly set something that stops the application from increasing the buffer's size? I don't know and I can't find any answer to that, so I was just wondering if there's any way to actually make my application to expand that buffer on its own.
You need to set a text limit with the EM_LIMITTEXT message. Otherwise:
Before EM_LIMITTEXT is called, the default limit for the amount of
text a user can enter in an edit control is 32,767 characters.