How would I simulate key presses in any type of aplication?

closed account (S6k9GNh0)
In most cases, you have an OS interface for keyboard presses which you interact with directly from your application. I would suggest a layer in-between the OS and your application where you feed key presses to the layer. Much easier, more portable.

Depending on your use case of course... CLI and Windowed applications are different.
Last edited on
Okay, how would I do that? What libary would I need to include?
closed account (S6k9GNh0)
Well, like I said, depending on use case.

If you're using a windowing application, most windowing tool kits have an abstract layer for events. This layer often allows you to push events yourself. SDL for instance has PushEvent:
So if I used this event in SDL and a key event, it would say to my operating system hey this user has clicked this key?
Iss that correct?
closed account (S6k9GNh0)
In my honest opinion, it would probably be best to hold off on event programming(key pressing results without hitting enter) until you are getting into actual graphics programing.

Thats just my personal opinion. Try learning SDL all together. Thats what im doing. Once i feel that i know enough C++, im going to continue learning SDL. Its not THAT hard to learn(just a little memorization), and theres a good tutorial site to get you started

Teaches you how to set everything up aswell.
Instead of just learning how to react to a key press, you should learn how to open up a window, put graphics on a screen, play sounds, etc., AND handle key presses
closed account (S6k9GNh0)
SDL doesn't correspond to just graphics. It can be used for its individual sub systems. You can use it to create window and use events without touching its audio, threading, or any of its other subsystems.

Also, lazyfoo tutorials are SDL 1.2 based. SDL 2 is available and stable. It's recommended for new use.

In addition, you shouldn't have to use SDL to accomplish this. There are other toolkits. They're mostly attached to windowing toolkits however, since its the windows that generate events.
Last edited on
Topic archived. No new replies allowed.