Hey @Gaal-Dornik,
In Cinema 4D you can bind a command to multiple shortcuts, but adding arguments is not possible. You would have to poll the keyboard yourself to distinguish such events.
Cheers,
Ferdinand
Result:
49a4bee1-8135-412f-b238-43d21184e071-image.png
Code:
"""Runs different code based on which keys are pressed.
Must be run as a Script Manager script. Pressing Shift+ALT+A while the script is invoked will
print "Foo", while pressing Ctrl+Alt+A will print "Bar".
See:
https://developers.maxon.net/docs/py/2024_0_0a/misc/inputevents.html
"""
import c4d
def CheckKeyboardState(*args: tuple[str]) -> bool:
"""Returns #True when the given key sequence is pressed, #False otherwise.
"""
result = []
for char in (n.upper() for n in args if isinstance(n, str)):
if char == "SHIFT":
c = c4d.KEY_SHIFT
elif char == "CTRL":
c = c4d.KEY_CONTROL
elif char == "ALT":
c = c4d.KEY_ALT
else:
c = ord(char)
bc = c4d.BaseContainer()
if not c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c, bc):
raise RuntimeError("Failed to poll the keyboard.")
result += [True if bc[c4d.BFM_INPUT_VALUE] == 1 else False]
return all(result)
def main() -> None:
"""
"""
if CheckKeyboardState("Shift", "Alt", "A"):
print ("Foo")
elif CheckKeyboardState("Ctrl", "Alt", "A"):
print ("Bar")
else:
print("None")
if __name__ == '__main__':
main()