bool UDozerGameViewportClient::InputKey(FViewport* Viewport, int32 ControllerId, FKey Key, EInputEvent Event, float AmountDepressed, bool bGamepad){ Super::InputKey(Viewport, ControllerId, Key, Event, AmountDepressed, bGamepad); if (ControllerId == 0){ if (Key.GetDisplayName().ToString().Equals(TEXT("Up"))){ Super::InputKey(Viewport, 1, FKey("W"), Event, AmountDepressed, bGamepad); } else if (Key.GetDisplayName().ToString().Equals(TEXT("Down"))){ Super::InputKey(Viewport, 1, FKey("S"), Event, AmountDepressed, bGamepad); } else if (Key.GetDisplayName().ToString().Equals(TEXT("Left"))){ Super::InputKey(Viewport, 1, FKey("A"), Event, AmountDepressed, bGamepad); } else if (Key.GetDisplayName().ToString().Equals(TEXT("Right"))){ Super::InputKey(Viewport, 1, FKey("D"), Event, AmountDepressed, bGamepad); } } return true; }
TOptional<FKey> FKeyStructCustomization::GetCurrentKey() const { TArray<void*> StructPtrs; PropertyHandle->AccessRawData(StructPtrs); if (StructPtrs.Num() > 0) { FKey* SelectedKey = (FKey*)StructPtrs[0]; if (SelectedKey) { for(int32 StructPtrIndex = 1; StructPtrIndex < StructPtrs.Num(); ++StructPtrIndex) { if (*(FKey*)StructPtrs[StructPtrIndex] != *SelectedKey) { return TOptional<FKey>(); } } return *SelectedKey; } } return FKey(); }
bool VRPNButtonInputDevice::ParseConfig(FConfigSection *InConfigSection) { TArray<const FString*> Buttons; InConfigSection->MultiFindPointer(FName(TEXT("Button")), Buttons); if(Buttons.Num() == 0) { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Config file for button device has no button mappings specified. Expeted field Button.")); return false; } for(const FString* ButtonString: Buttons) { int32 ButtonId; FString ButtonName; FString ButtonDescription; if(!FParse::Value(*(*ButtonString), TEXT("Id="), ButtonId) || !FParse::Value(*(*ButtonString), TEXT("Name="), ButtonName) || !FParse::Value(*(*ButtonString), TEXT("Description="), ButtonDescription)) { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Config not parse button. Expected: Button = (Id=#,Name=String,Description=String).")); continue; } // While NewKey is only valid for this iteration it will be copied in FKeyDetails below const FKey &NewKey = ButtonMap.Add(ButtonId, FKey(*ButtonName)); EKeys::AddKey(FKeyDetails(NewKey, FText::FromString(ButtonDescription), FKeyDetails::GamepadKey)); } return ButtonMap.Num() > 0; }
PyObject *py_ue_bind_key(ue_PyUObject *self, PyObject * args) { ue_py_check(self); char *key_name; int key; PyObject *py_callable; if (!PyArg_ParseTuple(args, "siO:bind_key", &key_name, &key, &py_callable)) { return NULL; } if (!PyCallable_Check(py_callable)) { return PyErr_Format(PyExc_Exception, "object is not a callable"); } UInputComponent *input = nullptr; if (self->ue_object->IsA<AActor>()) { input = ((AActor *)self->ue_object)->InputComponent; } else if (self->ue_object->IsA<UActorComponent>()) { UActorComponent *component = (UActorComponent *)self->ue_object; if (!component->GetOwner()) return PyErr_Format(PyExc_Exception, "component is still not mapped to an Actor"); input = component->GetOwner()->InputComponent; } else { return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component"); } if (!input) { return PyErr_Format(PyExc_Exception, "no input manager for this uobject"); } UPythonDelegate *py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewDelegate(input, py_callable, nullptr); FInputKeyBinding input_key_binding(FKey(UTF8_TO_TCHAR(key_name)), (const EInputEvent)key); input_key_binding.KeyDelegate.BindDelegate(py_delegate, &UPythonDelegate::PyInputHandler); input->KeyBindings.Add(input_key_binding); Py_RETURN_NONE; }
void SFlareKeyBind::SetKey(FKey NewKey, bool bCanReset, bool bNotify) { if (Key.IsValid()) { FKey CurrentKey = *Key; if (NewKey == *Key && bCanReset) { NewKey = FKey(); } *Key = NewKey; KeyText->SetText(NewKey == FKey() ? FString() : NewKey.ToString()); bWaitingForKey = false; FSlateApplication::Get().GetPlatformApplication().Get()->Cursor->Show(true); FSlateApplication::Get().ClearKeyboardFocus(EKeyboardFocusCause::SetDirectly); if (bNotify) { OnKeyBindingChanged.ExecuteIfBound( CurrentKey , NewKey ); } } }
void SFlareKeyBind::Construct(const FArguments& InArgs) { // Setup bWaitingForKey = false; DefaultKey = InArgs._DefaultKey; OnKeyBindingChanged = InArgs._OnKeyBindingChanged; const FFlareStyleCatalog& Theme = FFlareStyleSet::GetDefaultTheme(); // Parent constructor SButton::Construct(SButton::FArguments() .ButtonStyle(FCoreStyle::Get(), "NoBorder") .HAlign(HAlign_Fill) .VAlign(VAlign_Fill) .ContentPadding(FMargin(0)) .DesiredSizeScale(FVector2D(1, 1)) .ContentScale(FVector2D(1, 1)) .ButtonColorAndOpacity(FLinearColor::White) .ForegroundColor(FCoreStyle::Get().GetSlateColor("InvertedForeground")) ); // Layout ChildSlot [ SNew(SBorder) .BorderImage(&Theme.ButtonBackground) .HAlign(HAlign_Center) .VAlign(VAlign_Center) [ SAssignNew(KeyText, STextBlock) .TextStyle(&Theme.TextFont) ] ]; // Key data if (InArgs._Key.IsValid()) { Key = InArgs._Key; KeyText->SetText(*Key == FKey() ? FString() : Key->ToString()); } }
bool VRPNTrackerInputDevice::ParseConfig(FConfigSection *InConfigSection) { const FString* RotationOffsetString = InConfigSection->Find(FName(TEXT("RotationOffset"))); FVector RotationOffsetVector; float RotationOffsetAngleDegrees; if(RotationOffsetString == nullptr || !RotationOffsetVector.InitFromString(*RotationOffsetString) || !FParse::Value(*(*RotationOffsetString), TEXT("Angle="), RotationOffsetAngleDegrees)) { UE_LOG(LogVRPNInputDevice, Log, TEXT("Expected RotationOffsetAxis of type FVector and RotationOffsetAnlge of type Float when parsing tracker device. Rotation offset will be the indenty transform.")); RotationOffset = FQuat::Identity; } else { RotationOffsetVector.Normalize(); RotationOffset = FQuat(RotationOffsetVector, FMath::DegreesToRadians(RotationOffsetAngleDegrees)); RotationOffset.Normalize(); } const FString* PositioOffsetString = InConfigSection->Find(FName(TEXT("PositionOffset"))); if(PositioOffsetString == nullptr || !TranslationOffset.InitFromString(*PositioOffsetString)) { UE_LOG(LogVRPNInputDevice, Log, TEXT("Expected PositionOffset of type FVector (in device coordinates). Will use default of (0,0,0).")); TranslationOffset.Set(0, 0, 0); } FString *TrackerUnitsToUE4UnitsText = InConfigSection->Find(FName(TEXT("TrackerUnitsToUE4Units"))); if(TrackerUnitsToUE4UnitsText == nullptr) { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Expected to find TrackerUnitsToUE4UnitsText of type Float. Using default of 1.0f")); TrackerUnitsToUE4Units = 1.0f; } else { TrackerUnitsToUE4Units = FCString::Atof(*(*TrackerUnitsToUE4UnitsText)); } FString *FlipZAxisText = InConfigSection->Find(FName(TEXT("FlipZAxis"))); if(FlipZAxisText == nullptr) { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Expected to find FlipZAxis of type Boolean. Using default of false.")); FlipZAxis = false; } else { FlipZAxis = FCString::ToBool(*(*FlipZAxisText)); } TArray<const FString*> Trackers; InConfigSection->MultiFindPointer(FName(TEXT("Tracker")), Trackers); if(Trackers.Num() == 0) { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Config file for tracker device has no tracker mappings specified. Expeted field Tracker.")); return false; } bool bHasMotionControllers = false; for(const FString* TrackerString: Trackers) { int32 TrackerId; FString TrackerName; FString TrackerDescription; if(!FParse::Value(*(*TrackerString), TEXT("Id="), TrackerId) || !FParse::Value(*(*TrackerString), TEXT("Name="), TrackerName) || !FParse::Value(*(*TrackerString), TEXT("Description="), TrackerDescription)) { UE_LOG(LogVRPNInputDevice, Warning, TEXT("Config not parse tracker. Expected: Tracker = (Id=#,Name=String,Description=String).")); continue; } // see if this is a motion controller int PlayerId = -1; FParse::Value(*(*TrackerString), TEXT("PlayerId="), PlayerId); EControllerHand Hand = EControllerHand::Left; if(PlayerId >= 0) { UE_LOG(LogVRPNInputDevice, Log, TEXT("Found motion controller.")); bHasMotionControllers = true; FString HandString; if(FParse::Value(*(*TrackerString), TEXT("Hand="), HandString)) { if(HandString.Equals("Right")) { Hand = EControllerHand::Right; } } } UE_LOG(LogVRPNInputDevice, Log, TEXT("Adding new tracker: [%i,%s,%s,%i]."), TrackerId, *TrackerName, *TrackerDescription, PlayerId); const TrackerInput &Input = TrackerMap.Add(TrackerId, {FKey(*(TrackerName + "MotionX")), FKey(*(TrackerName + "MotionY")), FKey(*(TrackerName + "MotionZ")), FKey(*(TrackerName + "RotationYaw")), FKey(*(TrackerName + "RotationPitch")), FKey(*(TrackerName + "RotationRoll")), FVector(0), FQuat(EForceInit::ForceInit), PlayerId, Hand,false}); // Translation EKeys::AddKey(FKeyDetails(Input.MotionXKey, FText::FromString(TrackerName + " X position"), FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(Input.MotionYKey, FText::FromString(TrackerName + " Y position"), FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(Input.MotionZKey, FText::FromString(TrackerName + " Z position"), FKeyDetails::FloatAxis)); // Rotation EKeys::AddKey(FKeyDetails(Input.RotationYawKey, FText::FromString(TrackerName + " Yaw"), FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(Input.RotationPitchKey, FText::FromString(TrackerName + " Pitch"), FKeyDetails::FloatAxis)); EKeys::AddKey(FKeyDetails(Input.RotationRollKey, FText::FromString(TrackerName + " Roll"), FKeyDetails::FloatAxis)); } if(bHasMotionControllers) { UE_LOG(LogVRPNInputDevice, Log, TEXT("Adding this to the motion controller devices.")); IModularFeatures::Get().RegisterModularFeature(GetModularFeatureName(), this); } return true; }