Input Events

Input events are messages about input from the keyboard or from the mouse.

Distribution

All input events are stored in a central queue. The events are automatically sent to GeUserArea.InputEvent() if the user area is in focus. They can also be intercepted in GeDialog.Message().
Further, any code can either poll the event queue with GetInputEvent() or get the current input state with GetInputState().

Structure

Input events are stored in BaseContainer objects. The ID of the container is BFM_INPUT (this is also the ID to look for in GeDialog.Message()). The content of the container is:

BFM_INPUT_QUALIFIER

int

A bit mask with the qualifiers at the time when the event occurred:

QUALIFIER_NONE

None.

QUALIFIER_SHIFT

Shift key.

QUALIFIER_CTRL

Ctrl key.

QUALIFIER_MOUSEHIT

Indication in ObjectData.DetectHandle() that the user pressed the mouse.

For instance if QUALIFIER_MOUSEHIT and QUALIFIER_CTRL are set, a new element could be created.

BFM_INPUT_MODIFIERS

int

Same as BFM_INPUT_QUALIFIER but also contains bits > 0xf. Private.

BFM_INPUT_DEVICE

int

Device:

BFM_INPUT_MOUSE

Mouse.

BFM_INPUT_KEYBOARD

Keyboard.

BFM_INPUT_ASC

str

Contains the Unicode input from keyboard.

BFM_INPUT_CHANNEL

int

Contains the key or button. See also KEY.

BFM_INPUT_MOUSELEFT

Left mouse button.

BFM_INPUT_MOUSERIGHT

Right mouse button.

BFM_INPUT_MOUSEMIDDLE

Middle mouse button.

BFM_INPUT_MOUSEX1

Fourth mouse button.

BFM_INPUT_MOUSEX2

Five mouse button.

BFM_INPUT_MOUSEWHEEL

Mouse wheel.

BFM_INPUT_MOUSEMOVE

Mouse move.

BFM_INPUT_VALUE

int

Value of the input channel (Usually True/False or a int value, e.g. for scroll wheel data).

BFM_INPUT_VALUE_REAL

float

Channel value (e.g. pressure).

BFM_INPUT_X

int32

Mouse X position.

BFM_INPUT_Y

int32

Mouse Y position.

BFM_INPUT_Z

int32

Mouse Z position.

BFM_INPUT_TILT

int

Pen tilt.

BFM_INPUT_ORIENTATION

float

Pen rotation.

BFM_INPUT_P_ROTATION

float

Pen rotation around its own axis.

BFM_INPUT_FINGERWHEEL

int

Finger wheel.

BFM_INPUT_DOUBLECLICK

bool

Double click.

Note

The values for BFM_INPUT_DEVICE and BFM_INPUT_CHANNEL are used with GetInputState() and GetInputEvent() to get specific events only.

Continuous polling

There are no events for things like mouse-up or mouse-leave in Cinema 4D. The reason is that there is no reliable way to get such messages that is completely portable. Therefore it is sometimes necessary to enter a manual while loop that ends when the mouse is released. For example, to track how the user drags something with the left button down one would do:

state = c4d.BaseContainer()
while gui.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, state):
    if state.GetInt32(c4d.BFM_INPUT_VALUE)==0:
        break

    x = state.GetInt32(c4d.BFM_INPUT_X)
    y = state.GetInt32(c4d.BFM_INPUT_Y)

    #x, y

Note

Needless to say, try not to get caught in any infinite loops during such polls! If sending BFM_ACTION messages, for example fom a custom slider control, set the BFM_ACTION_INDRAG flag to True in those messages while in the loop.