Could someone test the following code for me? If you run this script and then run any application that should respond to the Esc key, pressing the Esc key should fail to do anything in your other application. Instead it should bring up a Macro Scheduler dialog and place Success! in the edit field of the dialog. The "other" application must have focus when you press the Esc key.
I tested using Windows Display Properties screen (right click the desktop then select "Properties" from the menu). Normally, when Display Properties has focus, pressing the esc key closes the window. After opening Display Properties then running the following script, pressing the Esc key while Display Properties has focus does nothing to Display Properties but instead displays the script's dialog then types into the edit field.
Please be aware: I'm not sure what the potential ramifications of these library functions might be. The script might not be implementing properly or might not close some memory gizmo properly so be sure to not run this before saving that important paper you've been typing on all day.
The dialog in the following script requires Macro Scheduler version 12 or greater.
Code: Select all
//The key_down onevent provides the key a task to do in the script
//VK27,0 is the Esc key with no modifier.
OnEvent>key_down,vk27,0,Paste
//The dialog allows some place for the key task to occur and
//gives us control over the script
Dialog>Dialog1
object Dialog1: TForm
Left = 465
Top = 178
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 223
ClientWidth = 439
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object Edit1: TEdit
Left = 45
Top = 40
Width = 244
Height = 21
TabOrder = 8
end
end
EndDialog>Dialog1
//A way to close the script
AddDialogHandler>Dialog1,,OnClose,Quit
//API function GlobalAddAtomA gives us an ID for the RegisterHotKey
//function's "ID" parameter. "JRL" is just a text string. For our
//purposes, it could be any alpha string shorter than 256 characters.
LibFunc>Kernel32,GlobalAddAtomA,GAAres,JRL
//API function RegisterHotKey required parameters. 1)A dialog handle
//2)An "ID" acquired using GlobalAddAtomA 3)A modifier key code allowing you to use
//ALT or CTRL or SHIFT with your key 4)The key's virtual key code
LibFunc>User32,RegisterHotKey,RHKres,dialog1.handle,GAAres,0,27
Label>Loop
Wait>0.01
Goto>Loop
SRT>Paste
Show>dialog1
SetDialogObjectFocus>dialog1,msEdit1
Wait>1
Send>Success!
END>Paste
SRT>Quit
//API function GlobalDeleteAtom clears the atom we earlier created
LibFunc>Kernel32,GlobalDeleteAtom,GDAres,GAAres
Exit>0
END>Quit