each key has to be pushed down, then released
like
keybd_event 50, 1, 0, 0 
keybd_event 50, 1, KEYEVENTF_KEYUP, 0 
where 50 is i believe the P key