Forum Discussion

kingmatte's avatar
kingmatte
New Contributor
9 years ago

How do I simulate holding down spacebar?

I'm trying to record a script that holds down the spacebar and does a region check while the spacebar is held down. Is this possible? I wasn't able to find anything in the Help documents about the spacebar key. I know about the [Hold] and [ReleaseLast] commands, but I don't know how to reference the right key.

  • I believe Keys releases all keys pressed when it finishes. You probably need KeyDown / KeyUp:

     

    myObj.SetFocus();
    Sys.Desktop.KeyDown(Win32API.VK_SPACE);
    // ... do something
    Sys.Desktop.KeyUp(Win32API.VK_SPACE);
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    I believe Keys releases all keys pressed when it finishes. You probably need KeyDown / KeyUp:

     

    myObj.SetFocus();
    Sys.Desktop.KeyDown(Win32API.VK_SPACE);
    // ... do something
    Sys.Desktop.KeyUp(Win32API.VK_SPACE);
  • djadhav's avatar
    djadhav
    Regular Contributor

    Keys(" ") should help you simulate the spacebar key.