Ctrl + button click?

Hi,

When clicking a button in the UI, i need to check whether Ctrl is pressed.

This code doesn’t work:

// This code is part of the function bound to the button click
if (ThisPC->IsInputKeyDown(EKeys::LeftControl))
{
	// DO CTRL + CLICK
}
else
{
	// DO CLICK
}

With this code i never visit the // DO CTRL+CLICK part.

Some people on the forum suggest that when the game focus on the UI, the player input is emptied and that this can be fixed using IsFocusable=false on the clicked button.

But this workaround doesn’t work in my case.

So is there a proper way to check if a key is pressed when clicking a UI button ?

Thanks
Cedric

Hey, haven’t tested this on buttons, but I am using modifier keys from slate application inside NativeOnMouseButtonDown()

FReply Widget::NativeOnMouseButtonDown(const FGeometry& geometry, const FPointerEvent& mouseEvent)
 {
     ...
 	const FModifierKeysState modifierKeys = FSlateApplication::Get().GetModifierKeys();
 	if (modifierKeys.IsLeftControlDown())
 	{
 		UE_LOG(LogTemp, Log, TEXT("CTRL DOWN"));
 	}
 	...
 }

Working like a charm, thank you so much :slight_smile:

Is it possible to detect that Ctrl+Click in UMG Widget Blueprint?

Override onKeyDown and store the state, sample it during onMouseDown. Assuming that by click you mean mouse button click. Maybe you meant a button widget click? In which case skip the onMouseDown.

1 Like

How to sample OnKeyDown during the OnMouseDown event?

You cannot, not directly. Instead, have the onKeyDown and Up set a bool variable state.

Query this variable during when mouse button goes down.

Okay, I’d tried that - is why I asked. Neither OnKeyUp or down was firing. So I ended up creating event on player character to bind to and used that.

The widget needs to be Focusable and be given focus to register keypresses.