The sampling_period parameter is expressed in milliseconds, and defines how frequently readings are updated. You may have to click inside the 3D window, so that it gets selected (e.g., active) and the key press events can be sent to the controller program.įirst, it is necessary to enable keyboard input by calling the wb_keyboard_enable function. These functions allow a controller program to read keys pressed on the computer keyboard when the 3D window of Webots is selected and the simulation is running. Period = wb_keyboard_get_sampling_period() WB_KEYBOARD_KEY, WB_KEYBOARD_SHIFT, WB_KEYBOARD_CONTROL, WB_KEYBOARD_ALT wb_keyboard_enable( sampling_period) WB_KEYBOARD_NUMPAD_RIGHT, WB_KEYBOARD_NUMPAD_DOWN, WB_KEYBOARD_NUMPAD_END, WB_KEYBOARD_NUMPAD_HOME, WB_KEYBOARD_NUMPAD_LEFT, WB_KEYBOARD_NUMPAD_UP, WB_KEYBOARD_RIGHT, WB_KEYBOARD_DOWN, WB_KEYBOARD_PAGEUP, WB_KEYBOARD_PAGEDOWN, Note : The keyboard predefined values are final integers located in the Keyboard class.WB_KEYBOARD_END, WB_KEYBOARD_HOME, WB_KEYBOARD_LEFT, WB_KEYBOARD_UP, Note : The keyboard predefined values are located into a (static) enumeration of the Keyboard class.įor example, Keyboard.CONTROL corresponds to the Control key stroke. The wb_keyboard_disable function should be used to stop the keyboard readings. The function can be called up to 7 times to detect up to 7 simultaneous keys pressed. If no key is currently pressed, the function will return -1.Ĭalling the wb_keyboard_get_key function a second time will return either -1 or the key code of another key which is currently simultaneously pressed. In this case, the returned value is the result of a binary OR between one of WB_KEYBOARD_SHIFT, WB_KEYBOARD_CONTROL or WB_KEYBOARD_ALT and the ASCII code (or the special value) of the pressed key according to which modifier key was pressed simultaneously. However, if a modifier key was pressed, the ASCII code (or special value) can be obtained by applying a binary AND between to the WB_KEYBOARD_KEY mask and the returned value. If no modifier (shift, control or alt) key is pressed, the key code is the ASCII code of the corresponding key or a special value (e.g., for the arrow keys). The returned value, if non-negative, is a key code corresponding to a key currently pressed. Note that the first key will be available only after the first sampling period elapsed.Īfter that, values can be read by calling the wb_keyboard_get_key function repeatedly until this function returns -1. These functions allow you to read a key pressed on the computer keyboard from a controller program while the 3D window of Webots is selected and the simulation is running.įirst, it is necessary to enable keyboard input by calling the wb_keyboard_enable function. WB_KEYBOARD_END, WB_KEYBOARD_HOME, WB_KEYBOARD_LEFT, WB_KEYBOARD_UP,
0 Comments
Leave a Reply. |