No.
You're programming at a lower level than a language with simple expressions to define rules like this.
Some ideas
Fundamentally, you're going to need to:
- Set up a timer for 500ms
- Set up a handler for keypresses
- Have your timer expiry handler say "You lost" if a boolean flag is set, or otherwise "send the ball flying into the net".
- Have your handler toggle that boolean flag if the keypress was Space
At a very basic level you could achieve this:
- directly with two worker threads, or
- crudely just by "waiting" for keypress activity (
select
, poll
, epoll
come to mind) with a timeout parameter (and ensure you don't reset the timeout if some other key were pressed instead), or
- with help from your operating system, using e.g. a POSIX timer (though be cautious; this will send you into platform-specific, C-compatible land, which is probably not where you ultimately want to end up).
Usually, though, to do things "properly", we'd embed this logic into functionality provided by some engine implementing an "event loop" (particularly common in games, or in I/O-heavy applications).
Further information is going to take a book to explain adequately, and is thus not really appropriate in this medium. However, at least now you know which topics to explore in existing material.
Potentially interesting anecdote
I once wrote a little scripting language for my application, so that I could just define neat, high-level rules and the "compiler" would make use of my event loop to implement them. It made maintenance and expansion of my application really easy, which was important at the time because the rules became fairly complex and the application was broad in scope. It's not uncommon for computer game engines to embed scripting abilities of their own (say, using the "Lua" language), to achieve the same goal.