Which Key Has Been Pressed?

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

Which Key Has Been Pressed?

Post by armsys » Fri Feb 04, 2011 9:21 am

Given AddDialogHandler>Dialog1,MSComboBox1,OnKeypress,DoCloseDialog, how to detect which key was presed in SRT>DoCloseDialog?
In the MSComboBox1, if the user presses ENTER, his acceptance is assumed.
If the user press ESC, his rejection is assumed.

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

Post by armsys » Fri Feb 04, 2011 9:30 am

OnEvent's Key_Down event definite a very specific keycode.
On the other hand, AddDialogHandler doesn't impose such restriction. The OnKeypress allows any key being pressed to trigger the subroutine. How could the called subroutine detect which key was pressed?

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Fri Feb 04, 2011 4:05 pm

Try this...

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 614
  Top = 225
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 212
  ClientWidth = 431
  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 MSComboBox1: tMSComboBox
    Left = 17
    Top = 31
    Width = 145
    Height = 21
    ItemHeight = 13
    TabOrder = 8
    Items.Strings = (
    'A'
    'B')
    ListText = 'A'#13#10'B'#13#10
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,MSComboBox1,OnSelect,GetRslt

Show>Dialog1,r

SRT>GetRslt
  GetDialogProperty>Dialog1,MSComboBox1,Text,rslt
  MDL>rslt
END>GetRslt
Thanks,
Jerry

[email protected]

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

Post by armsys » Fri Feb 04, 2011 4:12 pm

Hi Jerry,
Thanks for your help. However, your code obtains the text, not the keycode being pressed to trigger the SRT>GetRslt.

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

Post by Marcus Tettmar » Fri Feb 04, 2011 4:24 pm

In your OnKeyPress subroutine look at the value of SRTNAME_KEY. E.g.:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 750
  Top = 371
  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 MSComboBox1: tMSComboBox
    Left = 60
    Top = 26
    Width = 145
    Height = 21
    ItemHeight = 13
    TabOrder = 8
    Text = 'MSComboBox1'
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,MSComboBox1,OnKeyPress,DoKeyPress

Show>Dialog1,r

SRT>DoKeyPress
  MessageModal>Key pressed code was %DoKeyPress_Key%
END>DoKeyPress
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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

Post by Marcus Tettmar » Fri Feb 04, 2011 4:52 pm

Just been made aware that this feature of parameters passed into the subroutine by the event is not documented, though there is a sample script that comes with the software which shows it in action (Dialogs - MouseOver).

There's no list anywhere, so - right now - to find out what parameters, if any, are passed in by an event, stick a breakpoint at the top of the subroutine and then look at the watch list to see what is available. I'll try and find some time to write a blog post on this soon.
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 » Fri Feb 04, 2011 5:02 pm

Marcus,
Thanks for leaking the undocumented features.
Moreover, you show us the trick to expose other event-related properties as well.
Thanks.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Fri Feb 04, 2011 8:25 pm

mtettmar wrote:There's no list anywhere, so - right now - to find out what parameters, if any, are passed in by an event, stick a breakpoint at the top of the subroutine and then look at the watch list to see what is available. I'll try and find some time to write a blog post on this soon.
This is a great find... looking forward to your blog post on this.

Thanks and take care
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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

Post by Marcus Tettmar » Wed Feb 09, 2011 12:31 pm

Just in case you haven't already seen it I put together a short video and blog post on this topic here:

http://www.mjtnet.com/blog/2011/02/08/u ... arameters/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Feb 09, 2011 6:41 pm

Hi Marcus,

Yes, I watched it last night... the video was perfect for showing what is happening and how to use the debugger to see what is going on... thanks for making that available.

Please also consider, when time permits and maybe with the next maintenance release, adding a new Topic to the Help File that has a complete list of which parameters, if any, are passed in on various events.

There is a lot of power here... and seeing the full list will help us explore more of it.

Thanks and take care
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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

Post by Marcus Tettmar » Wed Feb 09, 2011 7:00 pm

Is anyone volunteering to compile such a list? I don't have one. It would take some time to try all permutations of all objects and all event handlers to find all parameters. Anyone offering?
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 » Thu Feb 10, 2011 3:08 am

Marcus,
Thanks for taking time to produce http://www.mjtnet.com/blog/2011/02/08/u ... arameters/. It's very helpful.

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