---
name: "joystick_sethandler"
section: "3"
platform: "linux"
package: "libsvga1-dev"
version: "1:1.4.3-33"
release: "Debian 7 (Wheezy)"
platforms: ["linux"]
url: "https://new.carta.tech/joystick_sethandler"
---

# joystick\_sethandler(3)

set the joystick event handler.

## NAME

joystick\_sethandler, joystick\_setdefaulthandler - set the joystick event handler.

## SYNOPSIS

**#include \<vgajoystick.h\>**\
 **typedef void (\****\_\_joystick\_handler***) (int** *event***, int** *number***, char** *value***, int** *joydev***);**

**void joystick\_sethandler(int** *joydev***, \_\_joystick\_handler** *jh***);**\
 **void joystick\_setdefaulthandler(int** *joydev***);**

## DESCRIPTION

By default, each call to [**joystick\_init**(3)](/joystick_init/3.md) enables the default handler for the opened joystick. This handler maintains a state table which can be read by the  [**joystick\_getaxis**(3)](/joystick_getaxis/3.md), [**joystick\_getbutton**(3)](/joystick_getbutton/3.md), **joystick\_button1\|2\|3\|4**(3), **joystick\_getb1\|2\|3\|4**(3), **joystick\_x\|y\|z**(3) and  **joystick\_getx\|y\|z**(3) functions.

If you define an own handler, the following parameters are passed:

*event* one of the following values:

**JOY\_EVENTBUTTONDOWN** a button was pressed.

**JOY\_EVENTBUTTONUP** a button was released.

**JOY\_EVENTAXIS** the joystick position was changed.

-

  All other values are reserved for future use.

*number* identifies the button or axis to which this event belongs.

*value* for axis events the new position in range **-128 .. 127**.**See** [**joystick\_getaxis**(3)](/joystick_getaxis/3.md) for further comments on the range.

*joydev* identifies the joystick affected (this allows to use one handler for many joysticks).

*joydev* **= -1** modifies the event handler of all currently open joystick devices.

## CAVEATS

This function is only available in ELF versions of svgalib. Due to backwards compatibility issues it cannot be used with shared a.out libs.

## SEE ALSO

[**svgalib**(7)](/svgalib/7.md), [**vgagl**(7)](/vgagl/7.md), [**libvga.config**(5)](/libvga.config/5.md), **joytest**(6), **mjoytest**(6), [**joystick\_init**(3)](/joystick_init/3.md), [**joystick\_close**(3)](/joystick_close/3.md), [**joystick\_update**(3)](/joystick_update/3.md), [**joystick\_getnumaxes**(3)](/joystick_getnumaxes/3.md), [**joystick\_getnumbuttons**(3)](/joystick_getnumbuttons/3.md), [**joystick\_getaxis**(3)](/joystick_getaxis/3.md), [**joystick\_getbutton**(3)](/joystick_getbutton/3.md), [**joystick\_button1**(3)](/joystick_button1/3.md), [**joystick\_getb1**(3)](/joystick_getb1/3.md), [**joystick\_x**(3)](/joystick_x/3.md), [**joystick\_getx**(3)](/joystick_getx/3.md).

## AUTHOR

The svgalib joystick handler was mostly done by Daniel Engstr\\"om \<daniel.engstrom@riksnett.no\>. Multiple joystick, VC switching support and code to glue it into svgalib by Michael Weller \<eowmob@exp-math.uni-essen.de\>. Part of the code is based on code from C. Smith and Vojtech Pavlik.
