Ask Your Question

Create a macro that press "Enter" automatic once.

asked 2017-08-16 21:50:48 +0200

WilliamLibreoffice gravatar image

I don't know how can I make that, I try, bun don't worked record Macro and press ENTER, so I Wold like have the code of the macro, anyone can help-me?

edit retag flag offensive close merge delete


It may be easier to help if you explained what you are trying to accomplish. The Enter key may react differently depending upon what you are doing.

Ratslinger gravatar imageRatslinger ( 2017-08-17 00:25:53 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2017-08-17 05:45:00 +0200

librebel gravatar image

Hello @WilliamLibreoffice,

To automatically press and release the ENTER -key in the current window, you could use the following Basic macro:

Sub simulate_KeyPress_RETURN()
REM Simulate a RETURN Key press ( and -release ) in the current Window.
REM NB. This can cause the triggering of window elements.
    Dim oKeyEvent As New
    oKeyEvent.Modifiers = 0     REM A combination of
    oKeyEvent.KeyCode   =               REM 1280.
    oKeyEvent.KeyChar   = chr( 13 )
    simulate_KeyPress( oKeyEvent )
End Sub

Sub simulate_KeyPress( oKeyEvent As )
REM Simulate a Key press ( and -release ) in the current Window.
REM NB. This can cause the triggering of window elements.
REM For example if there is a button currently selected in your form, and you call this method
REM while passing the KeyEvent for RETURN, then that button will be activated.
    If Not IsNull( oKeyEvent ) Then
        Dim oWindow As Object, oToolkit As Object
        oWindow = ThisComponent.CurrentController.Frame.getContainerWindow()
        oKeyEvent.Source = oWindow      
        oToolkit = oWindow.getToolkit()         REM
        oToolkit.keyPress( oKeyEvent )          REM methods of XToolkitRobot.
        oToolkit.keyRelease( oKeyEvent )
    End If
End Sub
edit flag offensive delete link more


Thanks man, I going to try that!

WilliamLibreoffice gravatar imageWilliamLibreoffice ( 2017-08-30 05:21:13 +0200 )edit

You're welcome :)

The same "RoboToolkit" allows to simulate Mouseclicks too...

librebel gravatar imagelibrebel ( 2017-08-30 06:02:07 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-08-16 21:50:48 +0200

Seen: 576 times

Last updated: Aug 17 '17