Assigning a key to a certain task in the scene #2672
-
Hi, How can I assign a keyboard key (or mouse) to do a certain task, or to make a change during the animation? Best, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Hi,
You can write a keyboard event in handle event function for any component
and get pressed key and finally do your task in animation loop
Best,
Behnam Binesh
Technical Manager
SiMedix, Tehran,Iran
[LinkedIn](https://www.linkedin.com/in/behnam-binesh-b128196b)
|
Beta Was this translation helpful? Give feedback.
-
Hi Behnam Binesh, Thank you for your comment. Can this just be done by modifying the c++ code of the component? Can't I do this in the XML or python script of the scene? Best, |
Beta Was this translation helpful? Give feedback.
-
Hi Zahra, You can surely assign a task to a key using Python scripting, you just have to define a function called Also, you can assign tasks to specific keys (such as arrow keys) by using the correspondences defined in Best, Camille |
Beta Was this translation helpful? Give feedback.
Hi Zahra,
You can surely assign a task to a key using Python scripting, you just have to define a function called
onKeypressedEvent
in a Python controller, and handle the key you are interested in with a simple condition such asif event['key']=='A'
You can find an example in the SofaPython3 plugin, in
SofaPython3\examples\liver-scriptcontroller.py
.Also, you can assign tasks to specific keys (such as arrow keys) by using the correspondences defined in
SofaPython3\constants\Key.py
, which you can import in your Python controller withimport Sofa.constants.Key
Best,
Camille