How to get the mouse events in an editor plugin?

I would like to react to user inputs in an editor plugin, how can I do that? In a game I can use a custom Pawn or a custom PlayerController but how can I do it in the editor?

I think I’ll find an answer in Rama’s wiki page about his vertex snapping editor plugin.

You can do it by extending FEdMode in your plugin:

class FPBEdMode : public FEdMode
{
public:
    const static FEditorModeID EM_PBPEdModeId;
public:
    FPBEdMode();
    virtual ~FPBEdMode();

	// FEdMode interface
	virtual void Enter() override;
	virtual void Exit() override;

    virtual void Render(const FSceneView* View, FViewport* Viewport, FPrimitiveDrawInterface* PDI) override;
    virtual void DrawHUD(FEditorViewportClient* ViewportClient, FViewport* Viewport, const FSceneView* View, FCanvas* Canvas) override;
    virtual void Tick(FEditorViewportClient* ViewportClient,float DeltaTime) override;

    virtual bool MouseEnter( FEditorViewportClient* ViewportClient,FViewport* Viewport,int32 x, int32 y );
    virtual bool MouseLeave( FEditorViewportClient* ViewportClient,FViewport* Viewport );
    virtual bool MouseMove(FEditorViewportClient* ViewportClient,FViewport* Viewport,int32 x, int32 y);
    virtual bool CapturedMouseMove( FEditorViewportClient* InViewportClient, FViewport* InViewport, int32 InMouseX, int32 InMouseY ) override;
    virtual bool InputKey(FEditorViewportClient* ViewportClient, FViewport* Viewport, FKey Key, EInputEvent Event) override;
    virtual bool InputAxis(FEditorViewportClient* InViewportClient, FViewport* Viewport, int32 ControllerId, FKey Key, float Delta, float DeltaTime) override;

	bool UsesToolkits() const override;
	// End of FEdMode interface

    FIntRect ViewRect;
    FViewMatrices ViewMatrices;

};

Note that you can get the ViewMatrices and the ViewRect in Render() to use those functions:

FSceneView::DeprojectScreenToWorld(
    ScreenPosition,
    ViewRect,
    ViewMatrices.GetInvViewMatrix(),
    ViewMatrices.GetInvProjMatrix(),
    RayOrigin,
    RayDirection
);

FSceneView::ProjectWorldToScreen(WorldPosition, ViewRect, ViewMatrices.GetViewProjMatrix(), ScreenPosition);

This enables to replace the PlayerController->ProjectWorldLocationToScreen() and PlayerController->DeprojectScreenPositionToWorld() that you would use in game.

You can also replace PlayerController->GetHitResultUnderCursor() with this:

 GetWorld()->LineTraceSingleByChannel(HitResult,
            RayOrigin,
            RayOrigin + RayDirection,
            TraceChannel);

Is it possible to manage mouse events with the standalone plugin?