Using Keyboard to control the model

Discussion in 'Simulation' started by Chinmay Swami, Jan 8, 2019.

  1. Hello Everyone ,

    I hope y'all had great holidays !!

    I just wanted to know is it possible to control your model using keyboard keys instead of using the mouse to change the control values. I am trying to modify the simulate.cpp example to incorporate the above functionality but I am not able to understand where to start.

    Thanks & Regards,
    Chinmay Swami
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    This is not supported, but you should be able to extend the code to do it. Look at the event handling code and add section to it as needed. Note however that the UI does not have a notion of active slider. So if you wanted to click on a slider, make it active, and then direct arrow key input to it, you have to implement your own code that keeps track of which slider is active. As far as the UI is concerned, the active element is active only if the mouse was pressed over it and has not yet been released.
  3. Hello Emo,

    Thanks for quick response.
    Actually I was planning on assigning two keys for each control one for increasing and the other for decreasing. So for example if I have 2 controls A,B then I would be using say Q and W keys to increase and decrease the value of control A. So like I am trying to remove the use of mouse completely as far as changing the control values is concerned. So for this I wont have to keep track of which slider is active right ?
    Actually I was able to write the code to detect the keys on the numpad pressed but I am not able to identify which part of the code represents the values of the sliders of the control. I only found the code for itemid == 0 which was the clear button in the function uiEvent. When I am dragging the slider the program is going into the same if statement of SECT_CONTROL. I found it out by just adding a print statement.

    Thanks & Regards,
    Chinmay Swami
    Last edited: Jan 10, 2019
  4. Figured it out !!! :)

    This is the code

    d->ctrl[2] = d->ctrl[2] + 0.1;
                    printf("\t d->ctrl[2] value is: %d", d->ctrl[2]);
                    mjui_update(SECT_CONTROL, -1, &ui1, &uistate, &con);
  5. Hello Chinmay,

    Could you elaborate more on where did you add that code and how you compile everything again, because I'm having some issues.