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).
Related
I'm curious to know how you can draw/update a certain region of the terminal/console. Is there any cross-platform libraries to do so?
The reason I want to know is because I am developing an instant message command line application, and I was curious to know how I can update the message viewer (where all the messages go) separately to where you write commands/text for other people in the chat. Obviously if I just tried to get input and write to cout then the input the user is entering and the messages would be "interfered" (by interfered I mean split in multiple lines).
I was thinking of using two stream objects: one to store the view (messages/output from the server) and one to store the input from the user, and just redraw whenever required. However, this seems inefficient and it requires me to clear the screen (in which case I don't know how to clear the screen efficiently and in a cross-platform manner).
I was also thinking of just switching to Qt/wxWidgets as it might simpler to make a GUI.
Use ncurses library to write text-based user interfaces in a terminal-independent manner.
As suggested by #Naruto, ncurses is a good way to go. At a much more basic level, you can also just use ANSI escape codes to move the cursor around the screen too:
For example, to position the cursor at line 5, column 23, you can enter this
echo -n "\033[5;23H"
There are more examples here.
I am writing a windows program (no mfc) and need to output a status line to the operator every few seconds or so. I tried using rich text boxes but after so many hours it seems to hang up. Does anybody have an suggestions on what I can use instead?
People mentioned that my buffers might have been exhausted. I thought I had planned for that. After I had about 1000 lines displayed I would take the first 500 and remove them using the select and cut options in rich text boxes. I still ran into the same problem.
This question appears relevant, and this one too. But they don't give any concrete recommendations for an alternative to rich text boxes.
You might try the Scintilla control (scintilla.org) which does not appear to have any hard limitations on text size. It has a permissive license. It is used by many text editors such as Notepad++, Notepad2, Code::Blocks, FlashDevelop. I haven't tried it personally but there from the documentation it looks easy to use it in a Windows API application. Of course, it might be overkill for your purposes.
If you keep appending to the text in the control every few seconds for hours then you are probably running into some memory constraint on the control or the process. I think you would have this problem with any control you choose given update frequence and how long you're running the program.
Have you considered implementing a simple circular buffer for the content of the text box? Say only keep the last hour's messages. You could maintain a separate log file for history if the operator needed to go back in time for hours.
I ended up writing my own control to do this, essentially duplicating the Output window in Visual Studio. It was a success, but it ended up being much more code than I thought it would be when I started - I insisted on features such as auto-scrolling when the cursor was on the last line, select/copy, bold text, etc. It was backed by a std::deque so I could limit the number of lines stored for the window.
Unfortunately the code belongs to a former employer so I can't share it here.
Hi so i'm making a game through the console window, and i was wondering if there was any way to just get maybe one or two text character's placement to change or disappear. Usually to accomplish this i would have to tell the console to re-type every single character and line all over again, but this just takes to long (1 second fps plus .5 second time spent re-typing the scene).
Is there some way i could re-fresh or change one or two lines or 'characters' seen on the console so so much time is not spent on waiting for the console to re-typing my 24 lines, each a string? (the scene made up of text)
Thanks! =)
btw... does anyone remember that little easter egg in windows which was an entire star wars movie made out of text in the console?? I want the game be smooth like that!
You'll need to use an external library to interface with the console as C++ doesn't have these capabilities, but it is possible.
My old goto for this sort of thing is ncurses. It's straightforward, quick to set up, and cross-platform. But it's old, and its age shows. (If you're on windows you'll have to use pdcurses; same capabilities, different package).
There are also console-specific ways of doing this. In particular, Windows provides an API for performing these sorts of actions.
You need ncurses library.
See console print w/o scrolling for reasons and examples.
Also google for the source to the rogue/urogue/nethack games which do that already.
I was wondering if you can add a link to a website in a C++ program running in the CMD Prompt type window (No GUI)
If it's possible can some one please give me a few examples?
You mean output text in the command prompt that the user can then click on? No, not unless the terminal supported it. Linux terminals usually autolink text that matches a URL pattern, so you could just printf("http://stackoverflow.com/\n"); and it would be clickable, but that's up to the terminal, not your program
When you write 'direct link' it is not clear if you mean clickable text or a means to open a url. At any rate, command line programs usually respond to command line parameters. Your program could open a url in the default browser in response to a command line flag. On Windows, you could call ShellExecute - on other systems, system might be appropriate.
It depends. In Windows, for example, yes, it's entirely possible, though somewhat non-trivial. You can receive mouse events via ReadConsoleInput, so in theory it's a fairly straightforward matter of reading the input event, and if it's a mouse click over the area you've defined as a link, you direct the user to the link as you see fit -- if you want to display the web site in text mode, that's possible (though, again, distinctly non-trivial). If you want to start up the user's normal web browser, that's a lot simpler (normally just ShellExecute the URL).
In reality, the details get a bit ugly. You have to enable mouse input for it to work at all. ReadConsoleInput gives you an INPUT_RECORD, which is a union of a number of different input record types, one of which is a mouse input record. By the time you get to react to a mouse click, your code is nested fairly deeply. None of it is unmanageable by any means, but unless you already have a fair amount of experience with Windows console programming, it might easily take most of a day (maybe even a bit more) before you have it working, rather than the hour or two you'd initially guess.
That, of course, is strictly for Windows -- if you ever want to port the code to another system, I'd guess there's a pretty good chance you'd be looking at a complete rewrite. For GUIs there are a fair number of cross-platform libraries, but text mode mouse operations aren't nearly so well supported.
First, some backstory:
I'm making what may amount to be a "roguelike" game so i can exersize some interesting ideas i've got floating around in my head. The gameplay isn't going to be a dungeon crawl, but in any case, the display is going to be done in a similar fasion, with simple ascii characters.
Being that this is a self exercise, I endeavor to code most of it myself.
Eventually I'd like to have the game runnable on arbitrarily large game worlds. (to the point where i envision havening the game networked and span over many monitors in a computer lab).
Right now, I've got some code that can read and write to arbitrary sections of a text console, and a simple partitioning system set up so that i can path-find efficiently.
And now the question:
I've ran some benchmarks, and the biggest bottleneck is the re-drawing of text consoles.
Having a game world that large will require an intelligent update of the display. I don't want to have to re-push my entire game buffer every frame... I need some pointers on how to set it up so that it only draws sections of the game have have been updated. (and not just individual characters as I've got now)
I've been manipulating the windows console via windows.h, but I would also be interested in getting it to run on linux machines over a puTTY client connected to the server.
I've tried adapting some video-processing routines, as there is nearly a 1:1 ratio between pixel and character, but I had no luck.
Really I want a simple explanation of some of the principles behind it. But some example (psudo)code would be nice too.
Use Curses, or if you need to be doing it yourself, read about the VTnnn control codes. Both of these should work on windows and on *nix terms and consoles (and Windows). You can also consult the nethack source code for hints. This will let you change characters on the screen wherever changes have happened.
I am not going to claim to understand this, but I believe this is close to the issue behind James Gosling's legendary Gosling Emacs redrawing code. See his paper, titled appropriately, "A Redisplay Algorithm", and also the general string-to-string correction problem.
Having a game world that large will
require an intelligent update of the
display. I don't want to have to
re-push my entire game buffer every
frame... I need some pointers on how
to set it up so that it only draws
sections of the game have have been
updated. (and not just individual
characters as I've got now)
The size of the game world isn't really relevant, as all you need to do is work out the visible area for each client and send that data. If you have a typical 80x25 console display then you're going to be sending just 2 or 3 kilobytes of data each time, even if you add in colour codes and the like. This is typical of most online games of this nature: update what the person can see, not everything in the world.
If you want to experiment with trying to find a way to cut down what you send, then feel free to do that for learning purposes, but we're about 10 years past the point where it is inefficient to update a console display in something approaching real time and it would be a shame to waste time fixing a problem that doesn't need fixing. Note that the PDF linked above gives an O(ND) solution whereas simply sending the entire console is half of O(N), where N is defined as the sum of the lengths of A and B and D.