views:

375

answers:

2

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.

+3  A: 

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

Stijn Sanders
This is a nice idea. But that has one problem - it doesn't span multiple forms. Ex. If an button opens a new form and then it does something in that new form. I'm thinking, maybe it's somehow possible to get the active form and then redirect the input there.
egon
I think I found the additional thing I need `Screen.ActiveForm`... (I'll test tomorrow...)
egon
ok almost, but this doesn't play nice with hotkeys...
egon
What do you understand under hotkeys?
Stijn Sanders
About Screen.ActiveForm, you should also have a look at the FindControl function defined in the Controls unit, you should be able to use it from the OnMessage event handler.
Stijn Sanders
I mean any hotkey that is handled by Windows (for example menu shortcuts). Because it doesn't drop these to windows message queue it doesn't handle those.
egon
+1  A: 

I have always used AutoIT's DLL for sending KeyStrokes as well as Blocking Keyboard and Mouse.

There is one thing and that is AutoIT can't block Ctrl+Alt+Del keys.

Do check it out.

HTH

Yogi Yang 007
That's a very interesting link. Thanks!
robsoft