Hi, im trying to realize left and right click on my widget. When I click the right or left mouse button - Click function fires and im want to get IsInputKeyDown and it always false. A feeling that IsInputKeyDown apply before event bind fires tick and again becomes to false or it happens after bind event tick. How to fix it or any alternatives?
bool UClickableWidget::CreateButton()
{
Button = Cast<UBorder>(GetWidgetFromName(FName("Border_PlusPlus")));
if (Button)
{
Button->OnMouseButtonDownEvent.BindUFunction(this, FName("Click"));
return true;
}
return false;
}
void UClickableWidget::Click()
{
if (GetWorld()->GetFirstPlayerController()->IsInputKeyDown(EKeys::LeftMouseButton))
{
LeftClick();
return;
}
if (GetWorld()->GetFirstPlayerController()->IsInputKeyDown(EKeys::RightMouseButton))
{
RightClick();
return;
}
}
I have decided this task. it looks like a garbage collection system principle. In Click function i set ClickCalled variable to true and on next tick check for it and here clicked button already testable.
void UClickableWidget::NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
{
Super::NativeTick(MyGeometry, InDeltaTime);
if (ClickCalled)
{
ClickCalled = false;
if (GetWorld()->GetFirstPlayerController()->IsInputKeyDown(EKeys::LeftMouseButton))
{
LeftClick();
return;
}
if (GetWorld()->GetFirstPlayerController()->IsInputKeyDown(EKeys::RightMouseButton))
{
RightClick();
return;
}
}
}
bool UClickableWidget::CreateButton()
{
Button = Cast<UBorder>(GetWidgetFromName(FName("Border_PlusPlus")));
if (Button)
{
Button->OnMouseButtonDownEvent.BindUFunction(this, FName("Click"));
return true;
}
return false;
}
void UClickableWidget::Click()
{
ClickCalled = true;
}