Announcement

Collapse
No announcement yet.

Trying to grab mouse button inputs

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Trying to grab mouse button inputs

    I'm trying to figure out which mouse button is being pressed but I'm not able to get a hit when I poll for specific mouse buttons being pressed.

    Code:
    void AStrategyHUD::DrawHUD()
    {
    	APlayerController* MyPC = GetOwningPlayerController();
    
    	FVector pos;
    	pos.Set(100, 20, 0);
    
    	if (MyPC->IsInputKeyDown(EKeys::SpaceBar))	<-gets triggered correctly, therefore the logic is sound and the syntax is right
    	{
    		DrawDebugString(GetWorld(), pos, "Spacebar Down");
    	}
    	
    	if (MyPC->IsInputKeyDown(EKeys::LeftMouseButton))	<-never gets triggered, regardless of mouse state
    	{
    		DrawDebugString(GetWorld(), pos, "LMB Down");
    	}
    	if (MyPC->IsInputKeyDown(EKeys::RightMouseButton))	<-never gets triggered, regardless of mouse state
    	{
    		DrawDebugString(GetWorld(), pos, "RMB Down");
    	}
    
    }
    Any ideas or reference examples I can use?

    #2
    Originally posted by Slayemin View Post
    I'm trying to figure out which mouse button is being pressed but I'm not able to get a hit when I poll for specific mouse buttons being pressed.

    Code:
    void AStrategyHUD::DrawHUD()
    {
    	APlayerController* MyPC = GetOwningPlayerController();
    
    	FVector pos;
    	pos.Set(100, 20, 0);
    
    	if (MyPC->IsInputKeyDown(EKeys::SpaceBar))	<-gets triggered correctly, therefore the logic is sound and the syntax is right
    	{
    		DrawDebugString(GetWorld(), pos, "Spacebar Down");
    	}
    	
    	if (MyPC->IsInputKeyDown(EKeys::LeftMouseButton))	<-never gets triggered, regardless of mouse state
    	{
    		DrawDebugString(GetWorld(), pos, "LMB Down");
    	}
    	if (MyPC->IsInputKeyDown(EKeys::RightMouseButton))	<-never gets triggered, regardless of mouse state
    	{
    		DrawDebugString(GetWorld(), pos, "RMB Down");
    	}
    
    }
    Any ideas or reference examples I can use?
    not 100% sure, and not curently in front of visual studio, but have you set bEnableClickEvents to true?
    Free Inventory System (BP AND C++ Version): Clicky Clicky
    Player Structure System (Houses!) (BP): Pew Pew Marketplace Version: Yoink!
    Howto: Create Dragable UMG Windows: Zoom Zoom

    Comment


      #3
      Originally posted by ruohki View Post
      not 100% sure, and not curently in front of visual studio, but have you set bEnableClickEvents to true?
      I added that in just to see if it was the missing problem. It was not.

      I've tried adding the code in other classes as well with no luck anywhere. I'm totally stumped, so I'm currently downloading the full engine source code so that I can step through the functions using the debugger

      Comment


        #4
        I'm doing something similar to this.

        So, as you can see, I have an action mapping which corresponds to two different input types: One for mouse input, one for keyboard input.
        Click image for larger version

Name:	0.png
Views:	1
Size:	91.3 KB
ID:	1064718

        I have a player controller which binds the action mappings to a function. For the sake of debugging purposes, I only care to know if the mapped function gets called. I have a breakpoint set within the called function to let me know if it got triggered. If I press the "1" button on the keyboard, the breakpoint is hit. This lets us know that the event is being fired correctly and is configured right. Since I also have the left mouse button bound to the same action mapping, clicking should fire the same event. It does not.
        Click image for larger version

Name:	1.png
Views:	1
Size:	64.7 KB
ID:	1064719

        I've looked over this input documentation very carefully, paying particular attention to the input processing procedure. I'm pretty sure I don't have an input enabled actor, so the next object to receive the input should be the player controller. Either something else is consuming the mouse click events before they get to the player controller, or the player controller is getting the mouse click events but the "IsInputKeyDown()" method is returning false when it should be returning true.


        Here is the code for my player controller:
        Code:
        //Constructor:
        AStrategyPlayerController::AStrategyPlayerController(const FObjectInitializer& ObjectInitializer)
        	: Super(ObjectInitializer), bIgnoreInput(false)
        {
        	PrimaryActorTick.bCanEverTick = true;
        	bHidden = false;
        	bShowMouseCursor = true;
        	bEnableClickEvents = true;
        	
        }
        
        void AStrategyPlayerController::SetupInputComponent()
        {
        	Super::SetupInputComponent();
        
        	InputHandler = ConstructObject<UGameInput>(UGameInput::StaticClass(), this);
        
        }
        
        void AStrategyPlayerController::ProcessPlayerInput(const float DeltaTime, const bool bGamePaused)
        {
        	if (IsInputKeyDown(EKeys::RightMouseButton) || IsInputKeyDown(EKeys::LeftMouseButton))   //<--- doesn't trigger
        	{
        		int a = 0;
        	}
        
        	if (WasInputKeyJustPressed(EKeys::LeftMouseButton))   //<--- doesn't trigger
        	{
        		int a = 0;
        	}
        	if (WasInputKeyJustPressed(EKeys::RightMouseButton))   //<--- doesn't trigger
        	{
        		int a = 0;
        	}
        	if (WasInputKeyJustPressed(EKeys::MiddleMouseButton))   //<--- doesn't trigger
        	{
        		int a = 0;
        	}
        	if (WasInputKeyJustPressed(EKeys::ThumbMouseButton))   //<--- doesn't trigger
        	{
        		int a = 0;
        	}
        	if (WasInputKeyJustPressed(EKeys::ThumbMouseButton2))   //<--- doesn't trigger
        	{
        		int a = 0;
        	}
        	if (WasInputKeyJustPressed(EKeys::SpaceBar))    //<---sanity check: It triggers!
        	{
        		int a = 0;
        	}
        
        	Super::ProcessPlayerInput(DeltaTime, bGamePaused);
        
        }

        Comment


          #5
          Okay, I have solved my own problem.

          I didn't know this, but if you enable "Project Settings -> Input -> Mouse Properties -> Use Mouse for Touch", ALL mouse button events will be registered as TOUCH events, NOT mouse button events. This means that WasInputKeyJustPressed(EKeys::LeftMouseButton) will never fire because internally the mouse button events create an "EKeys::Touch1" event. The fix is to not use mouse for touch.


          How did I figure this out?

          I downloaded the entire engine source code, rebuilt the engine, added my project to the engine, and used the debugger to step into the engine input source code. I found that internally they maintain an KeyStateMap array which contains a list of every input detected during that frame and my mouse inputs were not showing up, but touch inputs were. In addition, I added break points for mouse clicks and found that they were being added as touch events instead of individual key events. It only took me a few seconds to figure out what the problem really was. I couldn't have figured this out without the complete source code, so THANK YOU EPIC for releasing the full source!

          Comment


            #6
            I'm glad you figured it out.

            For someone who has a future similar problems you could also have done "showdebug input" console command which will show you a debug version of what the key state map thinks it is.

            Comment


              #7
              I also just came across this same issue with EKeys::LeftMouseButton not firing events.

              My solution however was:
              Changing the Default Viewport Mouse Capture Mode to CaptureDuringMouseDown
              Code:
              DefaultViewportMouseCaptureMode=CaptureDuringMouseDown
              in DefaultInput.ini

              Then my left mouse button events started working again!

              Click image for larger version

Name:	Screen Shot 2020-06-23 at 12.48.30 PM.png
Views:	149
Size:	73.0 KB
ID:	1779762

              (UE4 4.25.1 MacOS 10.15.4)
              Attached Files

              Comment

              Working...
              X