Windows – Bypass keyboard,mouse input and let SendInput pass

delphidelphi-7winapiwindows 7windows-vista

I'm making user definable key macros to a program. (Those macros are limited to that program.)

I'm using TApplicationEvents to record key messages. And then use SendInput to play them back. But I need to disable mouse and keyboard so it wouldn't interrupt playback.

I can't use JournalPlaybackProc and JournalRecordProc because they are subject to UAC, UIPI in Vista and Win7.

Is there a easy way to block mouse and keyboard input while still using SendInput. (A way that doesn't need heightened privileges.)

Also I need one escape key that stops playback.

EDIT:
TControl.Perform didn't work because it ignores hotkeys.

I thought of using reserved nibble (bits 25-28) in WM_KEY messages, but in the windows documentation it says it's reserved and do not use. What could be the consequences.

Best Answer

If you want the 'artificial input' to be limited to your own application, I wouldn't use SendInput. If you use TApplicationEvents.OnMessage to record messages, I would add a 'if not(PlayingBack) then' check in the OnMessage when playing back a macro and use Form1.Perform