Forum Discussion

ray_mosley's avatar
ray_mosley
Frequent Contributor
10 years ago

How to enter special key sequence in VBScript

I have a window object that pops up another window whenever CTRL+Shift+F12 is entered.  This works as designed manually, but I cannot find the magic sequence to reporduce it from my code.  Any suggestions?

 

The following sub is what I have tried:

 

Sub SpecialTestDriver
  Dim xx
  Dim myObj
  
  Set myObj = eval("Sys.Process(""enterpriseroommanager"").VCLObject(""fmCHRTSelectICD10Options"").VCLObject(""Panel2"")")
  myObj.SetFocus 
  Call CtrlShiftF12(myObj)
''''  Call CtrlShiftF12
  xx = 0
End Sub
Sub CtrlShiftF12(obj)
''''Sub CtrlShiftF12
 '***************************************************************************
 'Purpose: Enter CTRL+Shift+F12 in the objectt
 '
 'Inputs: 
 '  obj = object 
 'Returns:  NA
 '
 'Change History:
 '2015.06.03 HRM - Original creation
 '***************************************************************************
''''Sys.Desktop.KeyDown(Win32API.VK_CONTROL) ' Press Ctrl
''''Sys.Desktop.KeyDown(65)                  ' Press A
''''Sys.Desktop.KeyUp(65)                    ' Release A
''''Sys.Desktop.KeyUp(Win32API.VK_CONTROL)   ' Release Ctrl
'============= First attempt =======================
''''    obj.KeyDown(Win32API.VK_CONTROL) ' Press Ctrl
''''    obj.KeyDown(Win32API.VK_SHIFT)   ' Press Shift
''''    obj.KeyDown(Win32API.VK_F12)     ' Press F12
''''    obj.KeyUp(Win32API.VK_F12)       ' Release F12
''''    obj.KeyUp(Win32API.VK_SHIFT)     ' Release Shift
''''    obj.KeyUp(Win32API.VK_CONTROL)   ' Release Ctrl
'============= Second attempt =======================
''''    obj.Keys(Win32API.VK_CONTROL+Win32API.VK_SHIFT+Win32API.VK_F12)     ' Press Ctrl + Shift + F12
''''    obj.Keys("[CTRL]+[SHIFT]+[F12]")     ' Press Ctrl + Shift + F12
''''    obj.SendKeys("(^+{F12})")     ' Press Ctrl + Shift + F12
    obj.Keys("(^+{F12})")     ' Press Ctrl + Shift + F12
'============= Third attempt =======================
''''    Sys.Desktop.KeyDown(Win32API.VK_CONTROL) ' Press Ctrl
''''    Sys.Desktop.KeyDown(Win32API.VK_SHIFT)   ' Press Shift
''''    Sys.Desktop.KeyDown(Win32API.VK_F12)     ' Press F12
''''    Sys.Desktop.KeyUp(Win32API.VK_F12)       ' Release F12
''''    Sys.Desktop.KeyUp(Win32API.VK_SHIFT)     ' Release Shift
''''    Sys.Desktop.KeyUp(Win32API.VK_CONTROL)   ' Release Ctrl
End Sub    'CtrlShiftF12
  • That was my first attempt several days ago - it recorded but did not play back.

     

    What I finally got to work today was:

        obj.Keys("[Hold]^+[F12]{Release]")     ' Press Ctrl + Shift + F12

    Now I am on to the next problem...

  • ray_mosley's avatar
    ray_mosley
    Frequent Contributor

    That was my first attempt several days ago - it recorded but did not play back.

     

    What I finally got to work today was:

        obj.Keys("[Hold]^+[F12]{Release]")     ' Press Ctrl + Shift + F12

    Now I am on to the next problem...

  • Try recording a script when you enter CTRL+Shift+F12 in your window.

     

    What do you get?

  • The following sub is what I have tried:

     

    Sub SpecialTestDriver
      Dim xx
      Dim myObj
      
      Set myObj = eval("Sys.Process(""enterpriseroommanager"").VCLObject(""fmCHRTSelectICD10Options"").VCLObject(""Panel2"")")
      myObj.SetFocus 

     

    Sorry for the topic drift, but I am curious why you are using Eval to instantiate the object? In the code above, seems like it is not very fault tolerant in that if the Sys obect does not exist, you are going to end up with a variable containing a stub object that has only the Exists property. As a result, the call to the 'SetFocus' method will raise an exception since the stub object does not contain such a method. Consider the following which eliminates the need for double quoting the objects and affords more fault tolerance in case somethign prevented the creation of the object:

    Set myObj = Sys.Process("enterpriseroommanager").VCLObject("fmCHRTSelectICD10Options").VCLObject("Panel2")
       
       If myObj.Exists Then
          myObj.SetFocus
          ...
       End If