Mouse input does not work, mouse movement is also not being tracked.

Im semi new to monogame, but i know my logic is correct(code below) but when i move the mouse and click with it nothing happens. Please help!

class LevelTest : GameScreen
{
    Game game;

    InputManager input;

    private Player _player;

    private GameObject _num1;

    private List<Component> _components;

    MouseState _currentMouseState;
    MouseState _previousMouseState;

    public override void LoadContent(ContentManager Content, InputManager inputManager)
    {
        base.LoadContent(Content, inputManager);

        game = new Game();

        input = new InputManager(game);

        _player = new Player(Content.Load<Texture2D>("PlaceHolderPlayer"));

        _num1 = new GameObject(Content.Load<Texture2D>("PlaceHolderPlayer"));
        _num1.X = 0;
        _num1.Y = 0;

        _components = new List<Component>()
        {
            _player
        };

        _currentMouseState = Mouse.GetState();
        _previousMouseState = _currentMouseState;
    }

    public override void UnloadContent()
    {
        base.UnloadContent();
    }

    public override void Update(GameTime gameTime)
    {
        input.Update(gameTime);

        _previousMouseState = _currentMouseState;
        _currentMouseState = Mouse.GetState();

        foreach (var component in _components)
            component.Update(gameTime);

        _player.X = _currentMouseState.X;
        _player.Y = _currentMouseState.Y;

        if (_previousMouseState.LeftButton == ButtonState.Released && _currentMouseState.LeftButton == ButtonState.Pressed)
        {
            Console.WriteLine("Left button pressed");
        }
        else if (_previousMouseState.RightButton == ButtonState.Released && _currentMouseState.RightButton == ButtonState.Pressed)
        {   
            Console.WriteLine("Right button pressed");
        }
        else
            Console.WriteLine("No button pressed");
    }

    
    public override void Draw(SpriteBatch spriteBatch)
    {
        GameTime gameTime = new GameTime();

        base.Draw(spriteBatch);

        foreach(var component in _components)
            component.Draw(gameTime, spriteBatch);
    }
}

Try something like this:

if(_previousState.Position != _currentState.Position && (_currentState.LeftButton == ButtonState.Pressed)) ...

Sorry for the late response, but it didnt work. I dont think its my logic. It seems to not be registering input at all.

When do you call LoadContent? Once or for every frame? You have these lines which would pretty much mean the current and previous states are always equal:

_currentMouseState = Mouse.GetState();
_previousMouseState = _currentMouseState;

You could try adding this line at the start of your update loop to see if there’s at least something going on when you left click:

Console.WriteLine(Mouse.GetState().LeftButton);

I have this library to help with managing inputs btw: https://github.com/Apostolique/Apos.Input.

With mine you’d just create a MouseCondition:

ICondition leftButton = new MouseCondition(MouseButton.LeftButton)

Then you can check if it got pressed:

if (leftButton.Pressed()) {
    Console.WriteLine("Left button pressed");
}

You are deriving from GameScreen Class

the update method is called for every GameScreen regardless if its active or not. So I guess, you have severall GameScreen, each of them get’s the current state again so it’s only correct for the first GameScreen you added.

override “HandleInput” instead - which is only called for the currently active GameScreen

(and you don’t need to get the state in “LoadContent” - it’s a struct and will have default values anyway)

Where does the GameScreen class from?

As @reiti.net states you do not need to initialize your current and previous.

Are you calling your LevelTest.Update(…) in the main game loop, Game1.Update(…)?