예제 #1
0
FReply SWidget::OnKeyDown( const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent )
{
	if (SupportsKeyboardFocus())
	{
		EUINavigation Direction = FSlateApplicationBase::Get().GetNavigationDirectionFromKey( InKeyEvent );
		// It's the left stick return a navigation request of the correct direction
		if ( Direction != EUINavigation::Invalid )
		{
			return FReply::Handled().SetNavigation( Direction );
		}
		else if ( InKeyEvent.GetKey() == EKeys::Tab )
		{
			//@TODO: Really these uses of input should be at a lower priority, only occurring if nothing else handled them
			// For now this code prevents consuming them when some modifiers are held down, allowing some limited binding
			const bool bAllowEatingKeyEvents = !InKeyEvent.IsControlDown() && !InKeyEvent.IsAltDown() && !InKeyEvent.IsCommandDown();

			if (bAllowEatingKeyEvents)
			{
				EUINavigation MoveDirection = (InKeyEvent.IsShiftDown())
					? EUINavigation::Previous
					: EUINavigation::Next;
				return FReply::Handled().SetNavigation(MoveDirection);
			}
		}
	}
	return FReply::Unhandled();
}
예제 #2
0
FValorActionInputBinding UInputBlueprintLibrary::K2_GetInputAction(const FKeyEvent& KeyEvent)
{
	FValorActionInputBinding Binding;

	Binding.Key = KeyEvent.GetKey();
	Binding.KeyAsString = Binding.Key.GetDisplayName().ToString();

	Binding.bAlt = KeyEvent.IsAltDown();
	Binding.bCtrl = KeyEvent.IsControlDown();
	Binding.bShift = KeyEvent.IsShiftDown();
	Binding.bCmd = KeyEvent.IsCommandDown();

	return Binding;
}
예제 #3
0
FReply FTextEditHelper::OnKeyDown( const FKeyEvent& InKeyEvent, const TSharedRef< ITextEditorWidget >& TextEditor )
{
	const FKey Key = InKeyEvent.GetKey();

	if( Key == EKeys::Left )
	{
		return TextEditor->MoveCursor( FMoveCursor::Cardinal(
			// Ctrl moves a whole word instead of one character.	
			InKeyEvent.IsControlDown( ) ? ECursorMoveGranularity::Word : ECursorMoveGranularity::Character,
			// Move left
			FIntPoint( -1, 0 ),
			// Shift selects text.	
			InKeyEvent.IsShiftDown() ? ECursorAction::SelectText : ECursorAction::MoveCursor
		));
	}
	else if( Key == EKeys::Right )
	{
		return TextEditor->MoveCursor( FMoveCursor::Cardinal(
			// Ctrl moves a whole word instead of one character.	
			InKeyEvent.IsControlDown( ) ? ECursorMoveGranularity::Word : ECursorMoveGranularity::Character,
			// Move right
			FIntPoint( +1, 0 ),
			// Shift selects text.	
			InKeyEvent.IsShiftDown() ? ECursorAction::SelectText : ECursorAction::MoveCursor
		));
	}
	else if ( Key == EKeys::Up )
	{
		return TextEditor->MoveCursor( FMoveCursor::Cardinal(
			InKeyEvent.IsControlDown( ) ? ECursorMoveGranularity::Word : ECursorMoveGranularity::Character,
			// Move up
			FIntPoint( 0, -1 ),
			// Shift selects text.	
			InKeyEvent.IsShiftDown() ? ECursorAction::SelectText : ECursorAction::MoveCursor
		));
	}
	else if ( Key == EKeys::Down )
	{
		return TextEditor->MoveCursor( FMoveCursor::Cardinal(
			InKeyEvent.IsControlDown( ) ? ECursorMoveGranularity::Word : ECursorMoveGranularity::Character,
			// Move down
			FIntPoint( 0, +1 ),
			// Shift selects text.	
			InKeyEvent.IsShiftDown() ? ECursorAction::SelectText : ECursorAction::MoveCursor
		));
	}
	else if( Key == EKeys::Home )
	{
		// Go to the beginning of the document; select text if Shift is down.
		TextEditor->JumpTo(
			(InKeyEvent.IsControlDown() ) ? ETextLocation::BeginningOfDocument : ETextLocation::BeginningOfLine,
			(InKeyEvent.IsShiftDown()) ? ECursorAction::SelectText : ECursorAction::MoveCursor );

		return FReply::Handled();
	}
	else if ( Key == EKeys::End )
	{
		// Go to the end of the document; select text if Shift is down.
		TextEditor->JumpTo(
			(InKeyEvent.IsControlDown() ) ? ETextLocation::EndOfDocument : ETextLocation::EndOfLine,
			(InKeyEvent.IsShiftDown()) ? ECursorAction::SelectText : ECursorAction::MoveCursor );

		return FReply::Handled();
	}
	else if( Key == EKeys::Enter && !TextEditor->GetIsReadOnly() )
	{
		FScopedTextTransaction TextTransaction(TextEditor);

		TextEditor->OnEnter();

		return FReply::Handled();
	}
	else if( Key == EKeys::Delete && !TextEditor->GetIsReadOnly() )
	{
		// @Todo: Slate keybindings support more than one set of keys. 
		// Delete to next word boundary (Ctrl+Delete)
		if (InKeyEvent.IsControlDown() && !InKeyEvent.IsAltDown() && !InKeyEvent.IsShiftDown())
		{
			TextEditor->MoveCursor( FMoveCursor::Cardinal(
				ECursorMoveGranularity::Word, 
				// Move right
				FIntPoint(+1, 0),
				// selects text.	
				ECursorAction::SelectText
			));
		}

		FScopedTextTransaction TextTransaction(TextEditor);

		// Delete selected text
		TextEditor->DeleteChar();
		
		return FReply::Handled();
	}	
	else if( Key == EKeys::Escape )
	{
		return TextEditor->OnEscape();
	}

	// @Todo: Slate keybindings support more than one set of keys. 
	//Alternate key for cut (Shift+Delete)
	else if( Key == EKeys::Delete && InKeyEvent.IsShiftDown() && TextEditor->CanExecuteCut() )
	{
		// Cut text to clipboard
		TextEditor->CutSelectedTextToClipboard();
		
		return FReply::Handled();
	}

	// @Todo: Slate keybindings support more than one set of keys. 
	// Alternate key for copy (Ctrl+Insert) 
	else if( Key == EKeys::Insert && InKeyEvent.IsControlDown() && TextEditor->CanExecuteCopy() ) 
	{
		// Copy text to clipboard
		TextEditor->CopySelectedTextToClipboard();
		
		return FReply::Handled();
	}


	// @Todo: Slate keybindings support more than one set of keys. 
	// Alternate key for paste (Shift+Insert) 
	else if( Key == EKeys::Insert && InKeyEvent.IsShiftDown() && TextEditor->CanExecutePaste() )
	{
		// Paste text from clipboard
		TextEditor->PasteTextFromClipboard();
		
		return FReply::Handled();
	}

	// @Todo: Slate keybindings support more than one set of keys. 
	//Alternate key for undo (Alt+Backspace)
	else if( Key == EKeys::BackSpace && InKeyEvent.IsAltDown() && !InKeyEvent.IsShiftDown() && TextEditor->CanExecuteUndo() )
	{
		// Undo
		TextEditor->Undo();
		
		return FReply::Handled();
	}

	// @Todo: Slate keybindings support more than one set of keys. 
	// Delete to previous word boundary (Ctrl+Backspace)
	else if( Key == EKeys::BackSpace && InKeyEvent.IsControlDown() && !InKeyEvent.IsAltDown() && !InKeyEvent.IsShiftDown() && !TextEditor->GetIsReadOnly() )
	{
		FScopedTextTransaction TextTransaction(TextEditor);

		TextEditor->MoveCursor( FMoveCursor::Cardinal(
			ECursorMoveGranularity::Word, 
			// Move left
			FIntPoint(-1, 0), 
			ECursorAction::SelectText
		));
		TextEditor->BackspaceChar();

		return FReply::Handled();
	}


	// Ctrl+Y (or Ctrl+Shift+Z, or Alt+Shift+Backspace) to redo
	else if( !TextEditor->GetIsReadOnly() && ( ( Key == EKeys::Y && InKeyEvent.IsControlDown() ) ||
		( Key == EKeys::Z && InKeyEvent.IsControlDown() && InKeyEvent.IsShiftDown() ) ||
		( Key == EKeys::BackSpace && InKeyEvent.IsAltDown() && InKeyEvent.IsShiftDown() ) ) )
	{
		// Redo
		TextEditor->Redo();
		
		return FReply::Handled();
	}
	else if( !InKeyEvent.IsAltDown() && !InKeyEvent.IsControlDown() && InKeyEvent.GetKey() != EKeys::Tab && InKeyEvent.GetCharacter() != 0 )
	{
		// Shift and a character was pressed or a single character was pressed.  We will type something in an upcoming OnKeyChar event.  
		// Absorb this event so it is not bubbled and handled by other widgets that could have something bound to the key press.

		//Note: Tab can generate a character code but not result in a typed character in this box so we ignore it.
		return FReply::Handled();
	}
	else
	{
		return FReply::Unhandled();
	}
}