event listeners

Haven't really used anything like this in c++ before, but I know Java has something like this so I figure it's gotta be in c++ some where.

So I'm in a method of a class, and that method has a number of inputs within it. I want to set it up so if a user hits F2 on any of those inputs it will call a specific method also of the same class and then return to the same input the user was on originally.

How do I set something up to listen for the F2 and call the appropriate method?
You'll need:
1. Some way to asynchronously read keyboard input. If you're working from the console, curses can do this. Otherwise, it depends on what you're doing.
2. Depending on how the method used in #1 works, you may need a thread safe queue to pass events to the main thread, or the API may already provide an interface that encapsulates this queue internally.
3. A main loop to check for new events and react to them.
closed account (zb0S216C)
What you could do is have a separate process thread that spins( waits ) for the F2 key to be pressed. When a thread waits in a loop, it's called a Spinlock[1]. Of course, the thread, when executed, performs whatever you want it to.

Without an example code of some sort, understanding what you're asking is quite hard.

References:
[1]http://en.wikipedia.org/wiki/Spinlock


Wazzak
Last edited on
Topic archived. No new replies allowed.