Click to See Complete Forum and Search --> : keybd_event help!


C++N00bie
April 3rd, 2008, 01:36 PM
I'm trying to simulate a key press with the keybd_event function, and make it hold for a certain amount of time. But when I use the function, it just presses down and releases. Is there a way to simulate a key press and keep it depressed for a certain amount of time? thx

golanshahar
April 3rd, 2008, 04:50 PM
Do you mean something like that:


DWORD dwStartTime = ::GetTickCount();
DWORD dwHoldTime = 10000; // 10 seconds

while( (::GetTickCount() - dwStartTime) < dwHoldTime )
{
::keybd_event('A',0 ,0,0);
::Sleep(50);
}

::keybd_event('A',0,KEYEVENTF_KEYUP ,0);


:D

Cheers

Arjay
April 3rd, 2008, 08:31 PM
Check out the SendInput (http://msdn2.microsoft.com/en-us/library/ms646310.aspx) function in Msdn. It allows you to simulate key strokes, mouse clicks and more.