OnEvent>KeyDown Fails

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

OnEvent>KeyDown Fails

Post by armsys » Tue Jan 25, 2011 2:57 pm

I insert OnEvent>KEY_DOWN,VK_ESCAPE,0,DoCloseDialog before Show>Dialog1,ModalResult.
SRT>DoCloseDialog
CloseDialog>Dialog1
End>DoCloseDialog
During the display of Dialog1, pressing ESC won't close Dialog1.

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

Post by Marcus Tettmar » Tue Jan 25, 2011 3:30 pm

No, because you're showing the dialog modally. The OnEvent won't do anything while the dialog is closed.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Jan 25, 2011 3:43 pm

Okay, now I realize that. How to close a dialog by pressing ESC?
Of course, pressing a Cancel button would do the job. Pressing ESC seems more handy to close/abort a dialog.

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

Post by Marcus Tettmar » Tue Jan 25, 2011 3:59 pm

Set the Cancel property of your Cancel button to true. This means that pressing Escape will invoke it. Try this:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 435
  Top = 236
  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 MSButton1: tMSButton
    Left = 84
    Top = 56
    Width = 75
    Height = 25
    Cancel = True
    ModalResult = 2
    Caption = 'MSButton1'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 8
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

Show>Dialog1,r
Run the macro and then hit escape and you will see the dialog close.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Jan 25, 2011 4:12 pm

Marcus,
You're awesome. Your trick works brilliantly. Yes, it's listed in the Button Object Properties in the online manual. It nearly impossible to know all properties of all objects available in Macro Scheduler.
Thanks a lot.

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