Restarting a program with a key word - re looping? - c++

So I've made a program in class for a project, this is done using C++, which is a menu system with one sub menu, to then deliver correct directions from one location to another,
this involved many else and if statements as well as a while loop. however, i'm wondering if it is at all possible to make it so if the user enters a particular string, to restart from the beginning of the program? such as a small function which is a re director to the top of the code again? so if the user messes up on the first menu, they can type 'back' in and go back to the previous menu?
it sounds easy, and its simple, but i'm having trouble with it, and don't know what the best way to approach this would be, despite how minor it is!
Any help is appreciated
thanks!

Related

I need to keep a text static, so when I run the .exe the text won't disappear (go up) no matter how much I type

First of all, I need this just for a program than runs in console only.
So, I need a specific text to always be displayed in the console, in the same place, no matter how much other text appears below it. It can't "go up", it has to be shown always.
I don't know if there's actually a way/command, to do that. So I figured I could just clear the console (clear the screen) and show it, repeating this multiple times. But I've read in several similar questions that doing so is not actually safe or the correct way to go, and I can't find an actual answer on why it isn't safe.
So I was wondering, first why clearing the console is not safe?
And most importantly how should I approach this?
Sorry if it's not well written, I'm a little rusty with my English.
If running it in windows compiler only.

Moving cursor using code and opening folder

This is a very random and maybe a bit strange question that i thought of at 3AM. I was thinking about how code could make my day to day life easier. Every morning I wake up, open chrome to the facebook conversations with my boyfriend, and write "good morning". And thats when i thought about this hypothetical project(just out of curiosity, I wouldn't use it haha): making a code that i can just run that does all of this for me.
I could have a html file that could redirect to the facebook link(https://www.facebook.com/messages/t/boyfriend_name). But how would I go on to make the code open this file, then move the mouse to where its supposed to go (the white area where the user inputs the text) then insert the text then press send?
I'm not asking for any code help as I can imagine that is too much, but my question is: could this be achievable in C++?(This is what we've been studying at school so far). If not, what coding language should I use? Is the idea achievable without a vast knowledge in computer science? If yes, have you got any sources about opening files using C++, moving cursor etc.
Note:The OS this would happen on is Windows 10
To do what you want is possible by using AutoIT and to use it from C++ you can try AutoITX for C++. With AutoIT it's possible to detect windows, move the mouse and insert text, although a web page is like a blackbox to it, so you'll have to rely on relative pixel coordinates (it might not be very robust).

Problems with setting insertion point in a wxTextCtrl

I'm trying to implement a custom widget in wxWidgets (version 2.8.12), essentially a modified single line wxTextCtrl. It takes a text input that consists of two sets of 8-digit hexadecimal numbers separated by a space, and I want the control to automatically handle that space. For example, if the user types 1-8 in twice (no press of the space bar required), the resulting contents of the text control should be:
12345678 12345678
If the user were to then place their cursor after the first '3' and backspace three times, that space should automatically adjust as they edit, resulting in:
45678123 45678
Essentially, the space should be completely transparent to the user.
I have this, for the most part, done. The code is a bit long to paste here, so here is a Gist:
https://gist.github.com/036c1a90f77521a8653c
There is one bug, however, that I can't seem to fix- upon typing the ninth digit, it automatically inserts the space, but the cursor ends up right after the space, right behind the ninth digit.
All attempts to use wxTextCtrl::SetInsertionPoint() and wxTextCtrl::SetInsertionPointEnd() have shown no success, so I've come here as a last resort in hopes that somebody can point out what I'm doing wrong.
To assist in testing this widget out, I've prepared a very quick and dirty application containing the widget:
https://gist.github.com/cf3219eb47e2bfe85b38
Or click here to download the code as a tarball:
https://gist.github.com/gists/cf3219eb47e2bfe85b38/download
Just run make to clean, compile, and run the code all at once. You'll need wxWidgets 2.8.12 installed to compile, of course.
Mostly every other facet of this widget works exactly as I want it to- it is just this one very large problem that is keeping this from working. There is, however, one tiny bug that I'm curious about, and though it isn't a major concern I'd like to fix it some time.
The space will be automatically handled even upon deleting characters, even if you delete a selection- however, if the selection that you delete ends on the ninth digit, it won't reformat the contents of the control after the deletion.
If anybody can pinpoint the cause of that it would be appreciated, but the insertion point problem is obviously my main concern.
Thanks to anybody willing to help, I tried to provide as much information and explanation as possible- if I missed anything, please let me know.
Generally speaking, it's difficult to modify the input handling of a native control as it behaves differently under different platforms. I don't know if you tested your code under all (or at least more than one) of them already but I fully expect you to find more problems.
Instead of trying to do it on your own, I'd recommend that you look at wxMaskedEdit proposed for the addition to wxWidgets itself. It's not final yet but there is a preliminary version already and I think it could work with 2.8 too (although it's developed with 2.9, of course).

Change the ASCII of a typed character

Im looking to make a program that mixes up all the keyboard letters/ASCII values. Sort of like the software version of taking off the keyboard letters and moving them around... Is there any way to do this? Right now, Im using an infinite while loop with a GetAsyncKeyState() inside to get any typed letters, but I dont know how to take that information and change it and put it back into system... Any and all help is greatly appreciated.
Thanks!
This sounds like someone is trying to write some nasty program?
For Windows: The basic idea would be catching window messages (WM_KEYDOWN and WM_KEYUP) and change the key values/ids before passing them.
Depending on your version, this will require your code to run with administrator privileges.
I don't have any experience for other systems regarding this, but the basic idea would most likely be the same.

Text-to-speech from my file/database?

I've made a little alarm program that is supposed to say one of a few things. There's a similar program on macs, but I couldn't find it for Windows, so I just wrote it in C++. Right now, I'm using a text file. The format of the text file I am parsing should help you to understand how the program works:
alarmName_Wakeup //There's a prefix alarmName, so I know when one list starts and another ends.
Cock-a-doodle-doo! //One thing to say.
Get out of bed! //Another thing to say.
Hello. Would you like to buy some guava juice? //Yet another thing to say.
So, I'm basically just trying to have the alarm randomly read one of these lines of text every five minutes until the user goes to his or her computer and presses the hotkey or clicks 'Stop Alarm'. I haven't been able to figure out how to get text-to-speech from a file or a database, though. I always need to have the text pasted in notepad or something, which is really shoddy. Please, help me figure out how.
The closest I can find to what I'm looking for is Open-SAPI, which works for both Linux and Windows.