Input driver example
This example demonstrates how to hook Ano script functions to input driver.
Detroit engine is supplied with one input driver which supports USB classic NES gamepad. The device looks like the original NES gamepad but has USB plug at the end of the cord. For this example to work, you need that kind of gamepad, and input_driver_events_? parameter must contain something like this in application config (${prefix}/etc/input_driver.conf):
input_driver_enable = input_usb_classic_nes_gamepad.so input_driver_events_1 = input_usb_classic_nes_gamepad.so:bp=drv_bp|br=drv_br|kp=drv_kp|kr=drv_kr|xy=drv_xy|xyz=drv_xyz|ad=drv_ad
If program is unable to autodetect the gamepad, it must be set by hand:
input_driver_params_1 = input_usb_classic_nes_gamepad.so:device=/dev/uhid1
Compilation
Easiest way to get this example running is to go to examples directory in package root, and run:
$ ./build.sh input_driver
build.sh script compiles Ano script to C, copies source files in place and pops up instructions what to do next. Follow them. Check also examples/README for more info.
Preview
; ----------------------------------------------------------------------------------------------------------------------------------
; input_driver.ano
;
; To compile:
;
; $ ./build/ano ./examples/input_driver/input_driver.ano > \
; engine/dsl_ano.h
; ----------------------------------------------------------------------------------------------------------------------------------
;
; @ANO_SCRIPT_NAME input_driver
; @ANO_SCRIPT_VERSION 0.0.3
; @ANO_SCRIPT_DESCRIPTION Simple input driver event handler example
;
; @ANO_FLAGS_USE_PROTOS [ ]
; @ANO_FLAGS_VAR_NAME_SUBS [ ]
; @ANO_FLAGS_VAR_WARN_UNUSED [ ]
;
; Copyright © 2016-2026, Jani Salonen <salojan@goto10.co>
; All rights reserved.
;
; This example demonstrates how to hook Ano functions to input driver.
;
; For this example to work, input_driver_events_? parameter must contain
; something like this in application config (${prefix}/etc/input_driver.conf):
;
; input_driver_enable = input_usb_classic_nes_gamepad.so
; input_driver_events_1 = input_usb_classic_nes_gamepad.so:bp=drv_bp|br=drv_br|kp=drv_kp|kr=drv_kr|xy=drv_xy|xyz=drv_xyz|ad=drv_ad
;
; If program is unable to autodetect the gamepad, it must be set by hand:
;
; input_driver_params_1 = input_usb_classic_nes_gamepad.so:device=/dev/uhid1
;
main {
print "Waiting for events, press <ctrl-c> to break.\n"
}
_INPUTCB_BUTTONPRESS_ callback drv_bp (_button, _state, _pressure) {
dump _button
dump _state
dump _pressure
}
_INPUTCB_BUTTONRELEASE_ callback drv_br (_button, _state) {
dump _button
dump _state
}
_INPUTCB_KEYPRESS_ callback drv_kp (_button, _state, _pressure) {
dump _button
dump _state
dump _pressure
}
_INPUTCB_KEYRELEASE_ callback drv_kr (_button, _state) {
dump _button
dump _state
}
_INPUTCB_XY_ callback drv_xy (_x, _y) {
dump _x
dump _y
}
_INPUTCB_XYZ_ callback drv_xyz (_x, _y, _z) {
dump _x
dump _y
dump _z
}
_INPUTCB_ANGLEDIST_ callback drv_ad (_angle, _distance) {
dump _angle
dump _distance
}
; ------------------------------------------------------------------------------ ; input_driver.w2c ; ; To compile: ; ; $ ./build/widget ./examples/input_driver/input_driver.w2c > \ ; engine/widget_defs.h ; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------ ; input_driver.m2c ; ; To compile: ; ; $ ./build/menu ./examples/input_driver/input_driver.m2c > \ ; engine/menu_defs.h ; ------------------------------------------------------------------------------
Copyright © 2026, Jani Salonen <salojan at goto10 piste co>. Piste is finnish word and means dot. All rights reserved.