MCPcopy Create free account
hub / github.com/20tab/UnrealEnginePython / py_ue_bind_key

Function py_ue_bind_key

Source/UnrealEnginePython/Private/UEPyInput.cpp:423–471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

421}
422
423PyObject *py_ue_bind_key(ue_PyUObject *self, PyObject * args) {
424
425 ue_py_check(self);
426
427 char *key_name;
428 int key;
429 PyObject *py_callable;
430 if (!PyArg_ParseTuple(args, "siO:bind_key", &key_name, &key, &py_callable)) {
431 return NULL;
432 }
433
434 if (!PyCallable_Check(py_callable)) {
435 return PyErr_Format(PyExc_Exception, "object is not a callable");
436 }
437
438 UInputComponent *input = nullptr;
439
440 if (self->ue_object->IsA<AActor>()) {
441 input = ((AActor *)self->ue_object)->InputComponent;
442 }
443 else if (self->ue_object->IsA<UActorComponent>()) {
444 UActorComponent *component = (UActorComponent *)self->ue_object;
445 if (!component->GetOwner())
446 return PyErr_Format(PyExc_Exception, "component is still not mapped to an Actor");
447 input = component->GetOwner()->InputComponent;
448 }
449 else {
450 return PyErr_Format(PyExc_Exception, "uobject is not an actor or a component");
451 }
452
453 if (!input) {
454 return PyErr_Format(PyExc_Exception, "no input manager for this uobject");
455 }
456
457 UPythonDelegate *py_delegate = NewObject<UPythonDelegate>();
458 py_delegate->SetPyCallable(py_callable);
459 py_delegate->AddToRoot();
460
461 // allow the delegate to not be destroyed
462 self->python_delegates_gc->push_back(py_delegate);
463
464 FInputKeyBinding input_key_binding(FKey(UTF8_TO_TCHAR(key_name)), (const EInputEvent)key);
465 input_key_binding.KeyDelegate.BindDelegate(py_delegate, &UPythonDelegate::PyInputHandler);
466 input->KeyBindings.Add(input_key_binding);
467
468 Py_INCREF(Py_None);
469 return Py_None;
470
471}
472
473PyObject *py_ue_bind_pressed_key(ue_PyUObject *self, PyObject * args) {
474 ue_py_check(self);

Callers 2

py_ue_bind_pressed_keyFunction · 0.85
py_ue_bind_released_keyFunction · 0.85

Calls 1

SetPyCallableMethod · 0.45

Tested by

no test coverage detected