Assign ESCape key to hotkey

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Assign ESCape key to hotkey

Post by Marcus Tettmar » Tue Apr 17, 2007 4:10 pm

Contributed by jpuziano with thanks to JRL for his enhancements.
Original topic: http://www.mjtnet.com/forum/viewtopic.php?t=3752

Code: Select all

/*
=======================================================================
2007-04-16 09:55:08 Monday by jpuziano
ESC to ALT-F4 Converter

Written to test an idea - in response to this post:
Assign ESCape key to hotkey (t=3752)
=======================================================================
*/

//VK27=ESC key, 0=no modifier key
OnEvent>KEY_DOWN,VK27,0,User_Hit_Escape_Key

//Hit ALT-ESC to exit, 3=ALT key as modifier
OnEvent>KEY_DOWN,VK27,3,User_Wants_To_Exit

Message>ESC to ALT-F4 Converter Macro now turned on%CRLF%%CRLF%Press ALT-ESC to turn this macro off
Wait>2
CloseWindow>Message*
//When variable Keep_Running=0, we will Exit
Let>Keep_Running=1
//If variable EscTimeOut=0 Pressing esc will press Alt+F4
Let>EscTimeOut=0
//Variable will disallow EscTimeOut from equalling zero until a timeout has expired
Let>EscTimer=0
//Variable to adjust EscTimer timeout
Let>EscTimerMax=10

Label>start
//A short wait state will make this macro more responsive
//but too short will make it hog too much CPU... adjust as desired
Wait>0.01
If>%EscTimeOut%=1
  Add>EscTimer,1
EndIf
If>%EscTimer%>%EscTimerMax%
  Let>EscTimeOut=0
  Let>EscTimer=0
EndIf
If>Keep_Running=0,Exit
Goto>start

SRT>User_Hit_Escape_Key
If>EscTimeOut=1,SkipAltF4
Press ALT
Press F4
Release ALT
Let>EscTimeOut=1
Label>SkipAltF4
Let>EscTimer=0
END>User_Hit_Escape_Key

SRT>User_Wants_To_Exit
Let>Keep_Running=0
END>User_Wants_To_Exit

Label>Exit
Message>ESC to ALT-F4 Converter Macro now turned off
Wait>2
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts