Skip to main content
GameDev.net gamedev.net
🔒 Locked

[c++] Simulating a keypress

Started by Jubei12 Sep 17, 2005 at 8:19 PM 4 replies 1.4k views
Original Post
Jubei12
Jubei12
This may sound somewhat odd, but a group of people that I know want a program that would automatically simulate pressing the F5 (refresh) key every 5 to 10 seconds while it's on, effectively refreshing whatever window is selected currently. It would be even better if the program could detect when whatever page was finished loading and then refresh it again. I've been programming in C++ for about 3 years now, and alas, I have no idea how to program this function at all. Any information on this would be great, and the program itself doesn't have to be fancy at all, just do it's designated task. Thanks.
Hedos
Hedos
It's not something C++ specific, it's something OS specific.
On what operating system do you want to develop this for?

Probably Windows, which means you simply have to look in the Windows API documentation (http://msdn.microsoft.com/library/default.asp).

The function you are looking for is: keybd_event, Microsoft says it is deprecated and you should use SendInput instead tough.. but I personally have always used keybd_event without problems.

As for detecting when a web page would be completely loaded, that's going to be a little bit more difficult as it would require some interaction with the browser you are using.
Drew_Benton
Drew_Benton
This older thread should be of interest for you (Post 1, Post 2) for the replication of keystrokes and sending messages to a program.
Jubei12
Jubei12
Okay, checked it out on msdn...thanks. If i wanted to say, have it loop every 5 seconds and press the button, how would I set that up? Sleep()?
Any code examples would be nice...thanks.
Exponent
Exponent
you could make a thread and have an infinite for loop which sleeps(5000) at the end of each iteration, like:

void mythread(void){    for(;; Sleep(5000))    {        // do refresh here    }            }

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.