evdev

package module
v0.0.19-0...-c38c771 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2014 License: BSD-1-Clause Imports: 6 Imported by: 1

README

evdev

Note: This is work in progress. Use at your own risk.

evdev is a pure Go implementation of the Linux evdev API. It allows a Go application to track events from any devices mapped to /dev/input/event[X].

TODO

  • Better error handling. The Device type now mostly ignores ioctl errors once the device has been successfuly opened. This is done to simplify the API. Some of the SetXXX methods do return a boolean value to indicate success/failure, but this is not consistently applied. Some of them work by sending an Event struct to the device by queueing it in the Device.Outbox channel. Which in turn is processed in a separate goroutine (see Device.pollOutbox).

    We can currently not receive any return values from such an operation. This includes possible errors. Should we implement some sort of synchronous call mechanism for these kind of writes? Ideally we do want to keep all of the writes confined to the same goroutine.

    We do not necessarily need an actual error value, just a boolean indicating success or failure. ioctl errors are usually very non-descriptive anyway, so there is little point in passing them around.

Known issues

Permissions

Opening nodes in /dev/input may require root access. This means that our client applications do as well. To solve this, there are a couple of options.

The most sensible one is to use a udev rule to give device access to anyone in the input group. Then add yourself to this group. This hinges on the question whether or not your system uses udev. For Arch Linux, udev comes pre-installed as a part of systemd.

Here is a short listing of the steps to undertake to make this work, but we strongly advise that you read through the appropriate documentation on what udev rules are and how to safely create or edit them.

As root, perform the following steps:

$ mkdir -p /etc/udev/rules.d
$ nano /etc/udev/rules.d/99-input.rules

Put this in the file:

KERNEL=="event*", NAME="input/%k", MODE="660", GROUP="input"

Save and exit nano. Then create the input group and add yourself to it:

$ groupadd -f input
$ gpasswd -a <YOURUSERNAME> input

This will add any input devices to the input group. Only users who are in this group, will be able to read from them. Reboot your machine to make these changes take effect.

`/dev/input' should now list someting like this:

$ ls -l /dev/input/
total 0
drwxr-xr-x 2 root root     120 Sep  7 18:10 by-id
drwxr-xr-x 2 root root     140 Sep  7 18:10 by-path
crw-rw---- 1 root input 13, 64 Sep  7 18:10 event0
crw-rw---- 1 root input 13, 65 Sep  7 18:10 event1
crw-rw---- 1 root input 13, 74 Sep  7 18:10 event10
crw-rw---- 1 root input 13, 75 Sep  7 18:10 event11
crw-rw---- 1 root input 13, 76 Sep  7 18:10 event12
crw-rw---- 1 root input 13, 77 Sep  7 18:10 event13
crw-rw---- 1 root input 13, 78 Sep  7 18:10 event14
crw-rw---- 1 root input 13, 66 Sep  7 18:10 event2
crw-rw---- 1 root input 13, 67 Sep  7 18:10 event3
crw-rw---- 1 root input 13, 68 Sep  7 18:10 event4
crw-rw---- 1 root input 13, 69 Sep  7 18:10 event5
crw-rw---- 1 root input 13, 70 Sep  7 18:10 event6
crw-rw---- 1 root input 13, 71 Sep  7 18:10 event7
crw-rw---- 1 root input 13, 72 Sep  7 18:10 event8
crw-rw---- 1 root input 13, 73 Sep  7 18:10 event9
crw-r----- 1 root root  13, 63 Sep  7 18:10 mice
crw-r----- 1 root root  13, 32 Sep  7 18:10 mouse0

Usage

go get github.com/jteeuwen/evdev

References

License

Unless otherwise stated, all of the work in this project is subject to a 1-clause BSD license. Its contents can be found in the enclosed LICENSE file.

Documentation

Overview

evdev is a pure Go implementation of the Linux evdev API. It allows a Go application to track events from any devices mapped to `/dev/input/event[X]`.

Index

Constants

View Source
const (
	AbsX             = 0x00
	AbsY             = 0x01
	AbsZ             = 0x02
	AbsRX            = 0x03
	AbsRY            = 0x04
	AbsRZ            = 0x05
	AbsThrottle      = 0x06
	AbsRudder        = 0x07
	AbsWheel         = 0x08
	AbsGas           = 0x09
	AbsBrake         = 0x0a
	AbsHat0X         = 0x10
	AbsHat0Y         = 0x11
	AbsHat1X         = 0x12
	AbsHat1Y         = 0x13
	AbsHat2X         = 0x14
	AbsHat2Y         = 0x15
	AbsHat3X         = 0x16
	AbsHat3Y         = 0x17
	AbsPressure      = 0x18
	AbsDistance      = 0x19
	AbsTiltX         = 0x1a
	AbsTiltY         = 0x1b
	AbsToolWidth     = 0x1c
	AbsVolume        = 0x20
	AbsMisc          = 0x28
	AbsMTSlot        = 0x2f // MT slot being modified
	AbsMTTouchMajor  = 0x30 // Major axis of touching ellipse
	AbsMTTouchMinor  = 0x31 // Minor axis (omit if circular)
	AbsMTWidthMajor  = 0x32 // Major axis of approaching ellipse
	AbsMTWidthMinor  = 0x33 // Minor axis (omit if circular)
	AbsMTOrientation = 0x34 // Ellipse orientation
	AbsMTPositionX   = 0x35 // Center X touch position
	AbsMTPositionY   = 0x36 // Center Y touch position
	AbsMTToolTYPE    = 0x37 // Type of touching device
	AbsMTBlobId      = 0x38 // Group a set of packets as a blob
	AbsMTTrackingId  = 0x39 // Unique ID of initiated contact
	AbsMTPressure    = 0x3a // Pressure on contact area
	AbsMTDistance    = 0x3b // Contact hover distance
	AbsMTToolX       = 0x3c // Center X tool position
	AbsMTToolY       = 0x3d // Center Y tool position
	AbsMax           = 0x3f
	AbsCount         = AbsMax + 1
)

Absolute events describe absolute changes in a property. For example, a touchpad may emit coordinates for a touch location. A few codes have special meanings:

AbsDistance is used to describe the distance of a tool from an interaction surface. This event should only be emitted while the tool is hovering, meaning in close proximity to the device and while the value of the BtnTouch code is 0. If the input device may be used freely in three dimensions, consider AbsZ instead.

AbsMt<name> is used to describe multitouch input events.

View Source
const (
	WordBitSize  = 64
	WordByteSize = 8
)
View Source
const (
	EvSync                = 0x00 // Synchronisation events.
	EvKeys                = 0x01 // Absolute binary results, such as keys and buttons.
	EvRelative            = 0x02 // Relative results, such as the axes on a mouse.
	EvAbsolute            = 0x03 // Absolute integer results, such as the axes on a joystick or for a tablet.
	EvMisc                = 0x04 // Miscellaneous uses that didn't fit anywhere else.
	EvSwitch              = 0x05 // Used to describe stateful binary switches.
	EvLed                 = 0x11 // LEDs and similar indications.
	EvSound               = 0x12 // Sound output, such as buzzers.
	EvRepeat              = 0x14 // Enables autorepeat of keys in the input core.
	EvForceFeedback       = 0x15 // Sends force-feedback effects to a device.
	EvPower               = 0x16 // Power management events.
	EvForceFeedbackStatus = 0x17 // Device reporting of force-feedback effects back to the host.
	EvMax                 = 0x1f
	EvCount               = EvMax + 1
)

Event types

View Source
const (
	IdBus = iota
	IdVendor
	IdProduct
	IdVersion
)

IDs.

View Source
const (
	FFStatusStopped = 0x00
	FFStatusPlaying = 0x01
	FFStatusMax     = 0x01
)

Values describing the status of a force-feedback effect

View Source
const (
	FFRumble    = 0x50
	FFPeriodic  = 0x51
	FFConstant  = 0x52
	FFSpring    = 0x53
	FFFriction  = 0x54
	FFDamper    = 0x55
	FFInertia   = 0x56
	FFRamp      = 0x57
	FFEffectMin = FFRumble
	FFEffectMax = FFRamp
)

Force feedback effect types.

View Source
const (
	FFSquare      = 0x58
	FFTriangle    = 0x59
	FFSine        = 0x5a
	FFSawUp       = 0x5b
	FFSawDown     = 0x5c
	FFCustom      = 0x5d
	FFWaveformMin = FFSquare
	FFWaveformMax = FFCustom
)

Force feedback periodic effect types

View Source
const (
	FFGain       = 0x60
	FFAutoCenter = 0x61
	FFMax        = 0x7f
	FFCount      = FFMax + 1
)

Set Force feedback device properties

View Source
const (
	DirDown  = 0x0000 // 0 degrees
	DirLeft  = 0x4000 // 90 degrees
	DirUp    = 0x8000 // 180 degrees
	DirRight = 0xc000 // 270 degrees
)

Directions encoded in Effect.Direction

View Source
const (
	BusPCI       = 0x01
	BusISAPNP    = 0x02
	BusUSB       = 0x03
	BusHIL       = 0x04
	BusBluetooth = 0x05
	BusVirtual   = 0x06
	BusISA       = 0x10
	BusI8042     = 0x11
	BusXTKBD     = 0x12
	BusRS232     = 0x13
	BusGamePort  = 0x14
	BusParPort   = 0x15
	BusAmiga     = 0x16
	BusADB       = 0x17
	BusI2C       = 0x18
	BusHost      = 0x19
	BusGSC       = 0x1A
	BusAtari     = 0x1B
	BusSPI       = 0x1C
)
View Source
const (
	MtToolFinger = 0
	MtToolPen    = 1
	MtToolMax    = 1
)

Multitouch tools

View Source
const (
	/*	The InputPropPointer property indicates that the device is not transposed
		on the screen and thus requires use of an on-screen pointer to trace user's
		movements. Typical pointer devices: touchpads, tablets, mice; non-pointer
		device: touchscreen.

		If neither InputPropDirect or InputPropPointer are set, the property is
		considered undefined and the device type should be deduced in the
		traditional way, using emitted event types.
	*/
	InputPropPointer = 0x00

	/*	The InputPropDirect property indicates that device coordinates should be
		directly mapped to screen coordinates (not taking into account trivial
		transformations, such as scaling, flipping and rotating). Non-direct input
		devices require non-trivial transformation, such as absolute to relative
		transformation for touchpads. Typical direct input devices: touchscreens,
		drawing tablets; non-direct devices: touchpads, mice.

		If neither InputPropDirect or InputPropPointer are set, the property is
		considered undefined and the device type should be deduced in the
		traditional way, using emitted event types.
	*/
	InputPropDirect = 0x01

	/*	For touchpads where the button is placed beneath the surface, such that
		pressing down on the pad causes a button click, this property should be
		set. Common in clickpad notebooks and macbooks from 2009 and onwards.

		Originally, the buttonpad property was coded into the bcm5974 driver
		version field under the name integrated button. For backwards
		compatibility, both methods need to be checked in userspace.
	*/
	InputPropButtonPad = 0x02

	/*	Some touchpads, most common between 2008 and 2011, can detect the presence
		of multiple contacts without resolving the individual positions; only the
		number of contacts and a rectangular shape is known. For such
		touchpads, the semi-mt property should be set.

		Depending on the device, the rectangle may enclose all touches, like a
		bounding box, or just some of them, for instance the two most recent
		touches. The diversity makes the rectangle of limited use, but some
		gestures can normally be extracted from it.

		If InputPropSemiMT is not set, the device is assumed to be a true
		multi-touch device.
	*/
	InputPropSemiMT = 0x03

	InputPropMax   = 0x1f
	InputPropCount = InputPropMax + 1
)

Input device properties and quirks.

Normally, userspace sets up an input device based on the data it emits, i.e., the event types. In the case of two devices emitting the same event types, additional information can be provided in the form of device properties.

View Source
const (
	KeyReserved         = 0
	KeyEscape           = 1
	Key1                = 2
	Key2                = 3
	Key3                = 4
	Key4                = 5
	Key5                = 6
	Key6                = 7
	Key7                = 8
	Key8                = 9
	Key9                = 10
	Key0                = 11
	KeyMinus            = 12
	KeyEqual            = 13
	KeyBackSpace        = 14
	KeyTab              = 15
	KeyQ                = 16
	KeyW                = 17
	KeyE                = 18
	KeyR                = 19
	KeyT                = 20
	KeyY                = 21
	KeyU                = 22
	KeyI                = 23
	KeyO                = 24
	KeyP                = 25
	KeyLeftBrace        = 26
	KeyRightBrace       = 27
	KeyEnter            = 28
	KeyLeftCtrl         = 29
	KeyA                = 30
	KeyS                = 31
	KeyD                = 32
	KeyF                = 33
	KeyG                = 34
	KeyH                = 35
	KeyJ                = 36
	KeyK                = 37
	KeyL                = 38
	KeySemiColon        = 39
	KeyApostrophe       = 40
	KeyGrave            = 41
	KeyLeftShift        = 42
	KeyBackSlash        = 43
	KeyZ                = 44
	KeyX                = 45
	KeyC                = 46
	KeyV                = 47
	KeyB                = 48
	KeyN                = 49
	KeyM                = 50
	KeyComma            = 51
	KeyDot              = 52
	KeySlash            = 53
	KeyRightShift       = 54
	KeyKPAsterisk       = 55
	KeyLeftAlt          = 56
	KeySpace            = 57
	KeyCapsLock         = 58
	KeyF1               = 59
	KeyF2               = 60
	KeyF3               = 61
	KeyF4               = 62
	KeyF5               = 63
	KeyF6               = 64
	KeyF7               = 65
	KeyF8               = 66
	KeyF9               = 67
	KeyF10              = 68
	KeyNumLock          = 69
	KeyScrollLock       = 70
	KeyKP7              = 71
	KeyKP8              = 72
	KeyKP9              = 73
	KeyKPMinus          = 74
	KeyKP4              = 75
	KeyKP5              = 76
	KeyKP6              = 77
	KeyKPPlus           = 78
	KeyKP1              = 79
	KeyKP2              = 80
	KeyKP3              = 81
	KeyKP0              = 82
	KeyKPDot            = 83
	KeyZenkakuhankaku   = 85
	Key102ND            = 86
	KeyF11              = 87
	KeyF12              = 88
	KeyRO               = 89
	KeyKatakana         = 90
	KeyHiragana         = 91
	KeyHenkan           = 92
	KeyKatakanaHiragana = 93
	KeyMuhenkan         = 94
	KeyKPJPComma        = 95
	KeyKPEnter          = 96
	KeyRightCtrl        = 97
	KeyKPSlash          = 98
	KeySysRQ            = 99
	KeyRightAlt         = 100
	KeyLineFeed         = 101
	KeyHome             = 102
	KeyUp               = 103
	KeyPageUp           = 104
	KeyLeft             = 105
	KeyRight            = 106
	KeyEnd              = 107
	KeyDown             = 108
	KeyPageDown         = 109
	KeyInsert           = 110
	KeyDelete           = 111
	KeyMacro            = 112
	KeyMute             = 113
	KeyVolumeDown       = 114
	KeyVolumeUp         = 115
	KeyPower            = 116 // SC System Power Down
	KeyKPEqual          = 117
	KeyKPPlusMinus      = 118
	KeyPause            = 119
	KeyScale            = 120 // AL Compiz Scale (Expose)
	KeyKPComma          = 121
	KeyHangeul          = 122
	KeyHanguel          = KeyHangeul
	KeyHanja            = 123
	KeyYen              = 124
	KeyLeftMeta         = 125
	KeyRightMeta        = 126
	KeyCompose          = 127
	KeyStop             = 128 // AC Stop
	KeyAgain            = 129
	KeyProps            = 130 // AC Properties
	KeyUndo             = 131 // AC Undo
	KeyFront            = 132
	KeyCopy             = 133 // AC Copy
	KeyOpen             = 134 // AC Open
	KeyPaste            = 135 // AC Paste
	KeyFind             = 136 // AC Search
	KeyCut              = 137 // AC Cut
	KeyHelp             = 138 // AL Integrated Help Center
	KeyMenu             = 139 // Menu (show menu)
	KeyCalc             = 140 // AL Calculator
	KeySetup            = 141
	KeySleep            = 142 // SC System Sleep
	KeyWakeup           = 143 // System Wake Up
	KeyFile             = 144 // AL Local Machine Browser
	KeySendFile         = 145
	KeyDeleteFile       = 146
	KeyXFer             = 147
	KeyProg1            = 148
	KeyProg2            = 149
	KeyWWW              = 150 // AL Internet Browser
	KeyMSDOS            = 151
	KeyCoffee           = 152 // AL Terminal Lock/Screensaver
	KeyScreenlock       = KeyCoffee
	KeyDirection        = 153
	KeyCycleWindows     = 154
	KeyMail             = 155
	KeyBookmarks        = 156 // AC Bookmarks
	KeyComputer         = 157
	KeyBack             = 158 // AC Back
	KeyForward          = 159 // AC Forward
	KeyCloseCD          = 160
	KeyEjectCD          = 161
	KeyEjectCloseCD     = 162
	KeyNextSong         = 163
	KeyPlayPause        = 164
	KeyPreviousSong     = 165
	KeyStopCD           = 166
	KeyRecord           = 167
	KeyRewind           = 168
	KeyPhone            = 169 // Media Select Telephone
	KeyISO              = 170
	KeyConfig           = 171 // AL Consumer Control Configuration
	KeyHomepage         = 172 // AC Home
	KeyRefresh          = 173 // AC Refresh
	KeyExit             = 174 // AC Exit
	KeyMove             = 175
	KeyEdit             = 176
	KeyScrollUp         = 177
	KeyScrollDown       = 178
	KeyKPLeftParen      = 179
	KeyKPRightParen     = 180
	KeyNew              = 181 // AC New
	KeyRedo             = 182 // AC Redo/Repeat
	KeyF13              = 183
	KeyF14              = 184
	KeyF15              = 185
	KeyF16              = 186
	KeyF17              = 187
	KeyF18              = 188
	KeyF19              = 189
	KeyF20              = 190
	KeyF21              = 191
	KeyF22              = 192
	KeyF23              = 193
	KeyF24              = 194
	KeyPlayCD           = 200
	KeyPauseCD          = 201
	KeyProg3            = 202
	KeyProg4            = 203
	KeyDashboard        = 204 // AL Dashboard
	KeySuspend          = 205
	KeyClose            = 206 // AC Close
	KeyPlay             = 207
	KeyFastForward      = 208
	KeyBassBoost        = 209
	KeyPrint            = 210 // AC Print
	KeyHP               = 211
	KeyCanera           = 212
	KeySound            = 213
	KeyQuestion         = 214
	KeyEmail            = 215
	KeyChat             = 216
	KeySearch           = 217
	KeyConnect          = 218
	KeyFinance          = 219 // AL Checkbook/Finance
	KeySport            = 220
	KeyShop             = 221
	KeyAltErase         = 222
	KeyCancel           = 223 // AC Cancel
	KeyBrightnessDown   = 224
	KeyBrightnessUp     = 225
	KeyMedia            = 226
	KeySwitchVideoMode  = 227 // Cycle between available video  outputs (Monitor/LCD/TV-out/etc)
	KeyKBDIllumToggle   = 228
	KeyKBDIllumDown     = 229
	KeyKBDIllumUp       = 230
	KeySend             = 231 // AC Send
	KeyReply            = 232 // AC Reply
	KeyForwardMail      = 233 // AC Forward Msg
	KeySave             = 234 // AC Save
	KeyDocuments        = 235
	KeyBattery          = 236
	KeyBluetooth        = 237
	KeyWLAN             = 238
	KeyUWB              = 239
	KeyUnknown          = 240
	KeyVideoNext        = 241 // drive next video source
	KeyVideoPrevious    = 242 // drive previous video source
	KeyBrightnessCycle  = 243 // brightness up, after max is min
	KeyBrightnessZero   = 244 // brightness off, use ambient
	KeyDisplayOff       = 245 // display device to off state
	KeyWIMax            = 246
	KeyRFKill           = 247 // Key that controls all radios
	KeyMicMute          = 248 // Mute / unmute the microphone
	KeyOk               = 0x160
	KeySelect           = 0x161
	KeyGoto             = 0x162
	KeyClear            = 0x163
	KeyPower2           = 0x164
	KeyOption           = 0x165
	KeyInfo             = 0x166 // AL OEM Features/Tips/Tutorial
	KeyTime             = 0x167
	KeyVendor           = 0x168
	KeyArchive          = 0x169
	KeyProgram          = 0x16a // Media Select Program Guide
	KeyChannel          = 0x16b
	KeyFavorites        = 0x16c
	KeyEPG              = 0x16d
	KeyPVR              = 0x16e // Media Select Home
	KeyMHP              = 0x16f
	KeyLanguage         = 0x170
	KeyTitle            = 0x171
	KeySubtitle         = 0x172
	KeyAngle            = 0x173
	KeyZoom             = 0x174
	KeyMode             = 0x175
	KeyKeyboard         = 0x176
	KeyScreen           = 0x177
	KeyPC               = 0x178 // Media Select Computer
	KeyTV               = 0x179 // Media Select TV
	KeyTV2              = 0x17a // Media Select Cable
	KeyVCR              = 0x17b // Media Select VCR
	KeyVCR2             = 0x17c // VCR Plus
	KeySAT              = 0x17d // Media Select Satellite
	KeySAT2             = 0x17e
	KeyCD               = 0x17f // Media Select CD
	KeyTape             = 0x180 // Media Select Tape
	KeyRadio            = 0x181
	KeyTuner            = 0x182 // Media Select Tuner
	KeyPlayer           = 0x183
	KeyText             = 0x184
	KeyDVD              = 0x185 // Media Select DVD
	KeyAUX              = 0x186
	KeyMP3              = 0x187
	KeyAudio            = 0x188 // AL Audio Browser
	KeyVideo            = 0x189 // AL Movie Browser
	KeyDirectory        = 0x18a
	KeyList             = 0x18b
	KeyMemo             = 0x18c // Media Select Messages
	KeyCalender         = 0x18d
	KeyRed              = 0x18e
	KeyGreen            = 0x18f
	KeyYellow           = 0x190
	KeyBlue             = 0x191
	KeyChannelUp        = 0x192 // Channel Increment
	KeyChannelDown      = 0x193 // Channel Decrement
	KeyFirst            = 0x194
	KeyLast             = 0x195 // Recall Last
	KeyAB               = 0x196
	KeyNext             = 0x197
	KeyRestart          = 0x198
	KeySlow             = 0x199
	KeyShuffle          = 0x19a
	KeyBreak            = 0x19b
	KeyPrevious         = 0x19c
	KeyDigits           = 0x19d
	KeyTeen             = 0x19e
	KeyTwen             = 0x19f
	KeyVideoPhone       = 0x1a0 // Media Select Video Phone
	KeyGames            = 0x1a1 // Media Select Games
	KeyZoomIn           = 0x1a2 // AC Zoom In
	KeyZoomOut          = 0x1a3 // AC Zoom Out
	KeyZoomReset        = 0x1a4 // AC Zoom
	KeyWordProcessor    = 0x1a5 // AL Word Processor
	KeyEditor           = 0x1a6 // AL Text Editor
	KeySpreadsheet      = 0x1a7 // AL Spreadsheet
	KeyGraphicsEditor   = 0x1a8 // AL Graphics Editor
	KeyPresentation     = 0x1a9 // AL Presentation App
	KeyDatabase         = 0x1aa // AL Database App
	KeyNews             = 0x1ab // AL Newsreader
	KeyVoiceMail        = 0x1ac // AL Voicemail
	KeyAddressBook      = 0x1ad // AL Contacts/Address Book
	KeyMessenger        = 0x1ae // AL Instant Messaging
	KeyDisplayToggle    = 0x1af // Turn display (LCD) on and off
	KeySpellCheck       = 0x1b0 // AL Spell Check
	KeyLogoff           = 0x1b1 // AL Logoff
	KeyDollar           = 0x1b2
	KeyEuro             = 0x1b3
	KeyFrameBack        = 0x1b4 // Consumer - transport controls
	KeyframeForward     = 0x1b5
	KeyContextMenu      = 0x1b6 // GenDesc - system context menu
	KeyMediaRepeat      = 0x1b7 // Consumer - transport control
	Key10ChannelsUp     = 0x1b8 // 10 channels up (10+)
	Key10ChannelsDown   = 0x1b9 // 10 channels down (10-)
	KeyImages           = 0x1ba // AL Image Browser
	KeyDelEOL           = 0x1c0
	KeyDelEOS           = 0x1c1
	KeyInsLine          = 0x1c2
	KeyDelLine          = 0x1c3
	KeyFN               = 0x1d0
	KeyFNEsc            = 0x1d1
	KeyFNF1             = 0x1d2
	KeyFNF2             = 0x1d3
	KeyFNF3             = 0x1d4
	KeyFNF4             = 0x1d5
	KeyFNF5             = 0x1d6
	KeyFNF6             = 0x1d7
	KeyFNF7             = 0x1d8
	KeyFNF8             = 0x1d9
	KeyFNF9             = 0x1da
	KeyFNF10            = 0x1db
	KeyFNF11            = 0x1dc
	KeyFNF12            = 0x1dd
	KeyFN1              = 0x1de
	KeyFN2              = 0x1df
	KeyFND              = 0x1e0
	KeyFNE              = 0x1e1
	KeyFNF              = 0x1e2
	KeyFNS              = 0x1e3
	KeyFNB              = 0x1e4
	KeyBRLDot1          = 0x1f1
	KeyBRLDot2          = 0x1f2
	KeyBRLDot3          = 0x1f3
	KeyBRLDot4          = 0x1f4
	KeyBRLDot5          = 0x1f5
	KeyBRLDot6          = 0x1f6
	KeyBRLDot7          = 0x1f7
	KeyBRLDot8          = 0x1f8
	KeyBRLDot9          = 0x1f9
	KeyBRLDot10         = 0x1fa
	KeyNumeric0         = 0x200 // used by phones, remote controls,
	KeyNumeric1         = 0x201 // and other keypads
	KeyNumeric2         = 0x202
	KeyNumeric3         = 0x203
	KeyNumeric4         = 0x204
	KeyNumeric5         = 0x205
	KeyNumeric6         = 0x206
	KeyNumeric7         = 0x207
	KeyNumeric8         = 0x208
	KeyNumeric9         = 0x209
	KeyNumericStar      = 0x20a
	KeyNumericPound     = 0x20b
	KeyCameraFocus      = 0x210
	KeyWPSButton        = 0x211 // WiFi Protected Setup key
	KeyTouchpadToggle   = 0x212 // Request switch touchpad on or off
	KeyTouchpadOn       = 0x213
	KeyTouchpadOff      = 0x214
	KeyCameraZoomIn     = 0x215
	KeyCameraZoomOut    = 0x216
	KeyCameraUp         = 0x217
	KeyCameraDown       = 0x218
	KeyCameraLeft       = 0x219
	KeyCameraRight      = 0x21a
	KeyAttendantOn      = 0x21b
	KeyAttendantOff     = 0x21c
	KeyAttendantToggle  = 0x21d // Attendant call on or off
	KeyLightsToggle     = 0x21e // Reading light on or off

	// We avoid low common keys in module aliases so they don't get huge.
	KeyMinInteresting = KeyMute
	KeyMax            = 0x2ff
	KeyCount          = KeyMax + 1
)
Keys and buttons

Events take the form Key<name> or Btn<name>. For example, KeyA is used to represent the 'A' key on a keyboard. When a key is depressed, an event with the key's code is emitted with value 1. When the key is released, an event is emitted with value 0. Some hardware send events when a key is repeated. These events have a value of 2. In general, Key<name> is used for keyboard keys, and Btn<name> is used for other types of momentary switch events.

A few codes have special meanings:

  • BtnTool<name>:

  • These codes are used in conjunction with input trackpads, tablets, and touchscreens. These devices may be used with fingers, pens, or other tools. When an event occurs and a tool is used, the corresponding BtnTool<name> code should be set to a value of 1. When the tool is no longer interacting with the input device, the BtnTool<name> code should be reset to 0. All trackpads, tablets, and touchscreens should use at least one BtnTool<name> code when events are generated.

  • BtnTouch: BtnTouch is used for touch contact. While an input tool is determined to be within meaningful physical contact, the value of this property must be set to 1. Meaningful physical contact may mean any contact, or it may mean contact conditioned by an implementation defined property. For example, a touchpad may set the value to 1 only when the touch pressure rises above a certain value. BtnTouch may be combined with BtnTool<name> codes. For example, a pen tablet may set BtnToolPen to 1 and BtnTouch to 0 while the pen is hovering over but not touching the tablet surface.

  • BtnToolFinger, BtnToolDoubleTap, BtnToolTrippleTap, BtnToolQuadTap:

  • These codes denote one, two, three, and four finger interaction on a trackpad or touchscreen. For example, if the user uses two fingers and moves them on the touchpad in an effort to scroll content on screen, BtnToolDoubleTap should be set to value 1 for the duration of the motion. Note that all BtnTool<name> codes and the BtnTouch code are orthogonal in purpose. A trackpad event generated by finger touches should generate events for one code from each group. At most only one of these BtnTool<name> codes should have a value of 1 during any synchronization frame.

View Source
const (
	BtnMisc           = 0x100
	Btn0              = 0x100
	Btn1              = 0x101
	Btn2              = 0x102
	Btn3              = 0x103
	Btn4              = 0x104
	Btn5              = 0x105
	Btn6              = 0x106
	Btn7              = 0x107
	Btn8              = 0x108
	Btn9              = 0x109
	BtnMouse          = 0x110
	BtnLeft           = 0x110
	BtnRight          = 0x111
	BtnMiddle         = 0x112
	BtnSide           = 0x113
	BtnExtra          = 0x114
	BtnForward        = 0x115
	BtnBack           = 0x116
	BtnTask           = 0x117
	BtnJoystick       = 0x120
	BtnTrigger        = 0x120
	BtnThumb          = 0x121
	BtnThumb2         = 0x122
	BtnTop            = 0x123
	BtnTop2           = 0x124
	BtnPinkie         = 0x125
	BtnBase           = 0x126
	BtnBase2          = 0x127
	BtnBase3          = 0x128
	BtnBase4          = 0x129
	BtnBase5          = 0x12a
	BtnBase6          = 0x12b
	BtnDead           = 0x12f
	BtnGamepad        = 0x130
	BtnA              = 0x130
	BtnB              = 0x131
	BtnC              = 0x132
	BtnX              = 0x133
	BtnY              = 0x134
	BtnZ              = 0x135
	BtnTL             = 0x136
	BtnTR             = 0x137
	BtnTL2            = 0x138
	BtnTR2            = 0x139
	BtnSelect         = 0x13a
	BtnStart          = 0x13b
	BtnMode           = 0x13c
	BtnThumbL         = 0x13d
	BtnThumbR         = 0x13e
	BtnDigi           = 0x140
	BtnToolPen        = 0x140
	BtnTooLRubber     = 0x141
	BtnToolBrush      = 0x142
	BtnToolPencil     = 0x143
	BtnToolAirbrush   = 0x144
	BtnToolFinger     = 0x145
	BtnToolMouse      = 0x146
	BtnToolLens       = 0x147
	BtnToolQuintTap   = 0x148 // Five fingers on trackpad
	BtnTouch          = 0x14a
	BtnStylus         = 0x14b
	BtnStylus2        = 0x14c
	BtnToolDoubleTap  = 0x14d
	BtnToolTrippleTap = 0x14e
	BtnToolQuadTap    = 0x14f // Four fingers on trackpad
	BtnWheel          = 0x150
	BtnGearDown       = 0x150
	BtnGearUp         = 0x151
	BtnTriggerHappy   = 0x2c0
	BtnTriggerHappy1  = 0x2c0
	BtnTriggerHappy2  = 0x2c1
	BtnTriggerHappy3  = 0x2c2
	BtnTriggerHappy4  = 0x2c3
	BtnTriggerHappy5  = 0x2c4
	BtnTriggerHappy6  = 0x2c5
	BtnTriggerHappy7  = 0x2c6
	BtnTriggerHappy8  = 0x2c7
	BtnTriggerHappy9  = 0x2c8
	BtnTriggerHappy10 = 0x2c9
	BtnTriggerHappy11 = 0x2ca
	BtnTriggerHappy12 = 0x2cb
	BtnTriggerHappy13 = 0x2cc
	BtnTriggerHappy14 = 0x2cd
	BtnTriggerHappy15 = 0x2ce
	BtnTriggerHappy16 = 0x2cf
	BtnTriggerHappy17 = 0x2d0
	BtnTriggerHappy18 = 0x2d1
	BtnTriggerHappy19 = 0x2d2
	BtnTriggerHappy20 = 0x2d3
	BtnTriggerHappy21 = 0x2d4
	BtnTriggerHappy22 = 0x2d5
	BtnTriggerHappy23 = 0x2d6
	BtnTriggerHappy24 = 0x2d7
	BtnTriggerHappy25 = 0x2d8
	BtnTriggerHappy26 = 0x2d9
	BtnTriggerHappy27 = 0x2da
	BtnTriggerHappy28 = 0x2db
	BtnTriggerHappy29 = 0x2dc
	BtnTriggerHappy30 = 0x2dd
	BtnTriggerHappy31 = 0x2de
	BtnTriggerHappy32 = 0x2df
	BtnTriggerHappy33 = 0x2e0
	BtnTriggerHappy34 = 0x2e1
	BtnTriggerHappy35 = 0x2e2
	BtnTriggerHappy36 = 0x2e3
	BtnTriggerHappy37 = 0x2e4
	BtnTriggerHappy38 = 0x2e5
	BtnTriggerHappy39 = 0x2e6
	BtnTriggerHappy40 = 0x2e7
)

Button codes for mice and other devices.

View Source
const (
	LedNumLock    = 0x00
	LedCapsLock   = 0x01
	LedScrollLock = 0x02
	LedCompose    = 0x03
	LedKana       = 0x04
	LedSleep      = 0x05
	LedSuspend    = 0x06
	LedMute       = 0x07
	LedMisc       = 0x08
	LedMail       = 0x09
	LedCharging   = 0x0a
	LedMax        = 0x0f
	LedCount      = LedMax + 1
)

LED events are used for input and output to set and query the state of various LEDs on devices.

View Source
const (
	MiscSerial    = 0x00
	MiscPulseLed  = 0x01
	MiscGesture   = 0x02
	MiscRaw       = 0x03
	MiscScan      = 0x04
	MiscTimestamp = 0x05
	MiscMax       = 0x07
	MiscCount     = MiscMax + 1
)

Miscellaneous events are used for input and output events that do not fall under other categories.

MiscTimestamp has a special meaning. It is used to report the number of microseconds since the last reset. This event should be coded as an uint32 value, which is allowed to wrap around with no special consequence. It is assumed that the time difference between two consecutive events is reliable on a reasonable time scale (hours). A reset to zero can happen, in which case the time since the last event is unknown. If the device does not provide this information, the driver must not provide it to user space.

View Source
const (
	RelX      = 0x00
	RelY      = 0x01
	RelZ      = 0x02
	RelRX     = 0x03
	RelRY     = 0x04
	RelRZ     = 0x05
	RelHWheel = 0x06
	RelDial   = 0x07
	RelWheel  = 0x08
	RelMisc   = 0x09
	RelMax    = 0x0f
	RelCount  = RelMax + 1
)

Relative events describe relative changes in a property. For example, a mouse may move to the left by a certain number of units, but its absolute position in space is unknown. If the absolute position is known, EvAbsolute codes should be used instead of EvRelative codes.

RelWheel and RelHWheel are used for vertical and horizontal scroll wheels, respectively.

View Source
const (
	RepDelay  = 0x00
	RepPeriod = 0x01
	RepMax    = 0x01
	RepCount  = RepMax + 1
)

Repeat events are used for specifying autorepeating events.

View Source
const (
	Keyboard = iota
	Mouse
	Joystick
)

List of device types.

These are used to look for specific input device types using evdev.Find().

The returned devices may not necessarily be an actual keyboard or mouse, etc. Just a device which can behave like one. For instance: Mouse may return a trackpad, a multi-touch screen and an actual mouse if all of these happen to be connected. It is up to the host to figure out which one to use.

View Source
const (
	SndClick = 0x00
	SndBell  = 0x01
	SndTone  = 0x02
	SndMax   = 0x07
	SndCount = SndMax + 1
)

Sound events are used for sending sound commands to simple sound output devices.

View Source
const (
	SwLid                = 0x00        // set = lid shut
	SwTabletMode         = 0x01        // set = tablet mode
	SwHeadphoneInsert    = 0x02        // set = inserted
	SwRFKillAll          = 0x03        // rfkill master switch, type "any"; set = radio enabled
	SwRadio              = SwRFKillAll // deprecated
	SwMicrophoneInsert   = 0x04        // set = inserted
	SwDock               = 0x05        // set = plugged into dock
	SwLineoutInsert      = 0x06        // set = inserted
	SwJackPhysicalInsert = 0x07        // set = mechanical switch set
	SwVideoOutInsert     = 0x08        // set = inserted
	SwCameraLensCover    = 0x09        // set = lens covered
	SwKeypadSlide        = 0x0a        // set = keypad slide out
	SwFrontProximity     = 0x0b        // set = front proximity sensor active
	SwRotateLock         = 0x0c        // set = rotate locked/disabled
	SwLineInInsert       = 0x0d        // set = inserted
	SwMax                = 0x0f
	SwCount              = SwMax + 1
)

Switch events describe stateful binary switches. For example, the SwLid code is used to denote when a laptop lid is closed.

Upon binding to a device or resuming from suspend, a driver must report the current switch state. This ensures that the device, kernel, and userspace state is in sync.

Upon resume, if the switch state is the same as before suspend, then the input subsystem will filter out the duplicate switch state reports. The driver does not need to keep the state of the switch at any time.

View Source
const (
	SynReport = iota
	SynConfig
	SynMTReport
	SynDropped
)

Synchronization event values are undefined. Their usage is defined only by when they are sent in the evdev event stream.

SynReport is used to synchronize and separate events into packets of input data changes occurring at the same moment in time. For example, motion of a mouse may set the RelX and RelY values for one motion, then emit a SynReport. The next motion will emit more RelX and RelY values and send another SynReport.

SynConfig: to be determined.

SynMTReport is used to synchronize and separate touch events. See the multi-touch-protocol.txt document for more information.

SynDropped is used to indicate buffer overrun in the evdev client's event queue. Client should ignore all events up to and including next SynReport event and query the device (using EVIOCG* ioctls) to obtain its current state.

View Source
const EvVersion = 0x010001
View Source
const (
	// Kernel should perform lookup in keymap by @index instead of @scancode
	InputKeymapByIndex = 1 << iota
)

KeymapEntry.Flags values. They specify how the kernel should handle a keymap request.

Variables

This section is empty.

Functions

func IsJoystick

func IsJoystick(dev *Device) bool

IsJoystick returns true if the given device qualifies as a joystick.

func IsKeyboard

func IsKeyboard(dev *Device) bool

IsKeyboard returns true if the given device qualifies as a keyboard.

func IsMouse

func IsMouse(dev *Device) bool

IsMouse returns true if the given device qualifies as a mouse.

Types

type AbsInfo

type AbsInfo struct {
	Value      int32 // Current value of the axis,
	Minimum    int32 // Lower limit of axis.
	Maximum    int32 // Upper limit of axis.
	Fuzz       int32 // ???
	Flat       int32 // Size of the 'flat' section.
	Resolution int32 // Size of the error that may be present.
}

AbsInfo provides information for a specific absolute axis. This applies to devices which support EvAbsolute events.

type Bitset

type Bitset []Word

Bitset defines a set of bit values.

func NewBitset

func NewBitset(bits int) Bitset

NewBitset creates a new bitset of the given size.

func (Bitset) Bytes

func (b Bitset) Bytes() []byte

Bytes returns the bitset as a byte slice. This is the same memory, so any changes to the returned slice, will affect the bitset.

func (Bitset) Len

func (b Bitset) Len() int

Len returns the number of bits in the set.

func (Bitset) Set

func (b Bitset) Set(i int)

Set sets the bit at the given index.

func (Bitset) Test

func (b Bitset) Test(i int) bool

Test returns true if the bit at the given index is set.

func (Bitset) Unset

func (b Bitset) Unset(i int)

Unset clears the bit at the given index.

type ConditionEffect

type ConditionEffect struct {
	RightSaturation uint16
	LeftSaturation  uint16
	RightCoeff      int16
	LeftCoeff       int16
	Deadband        uint16
	Center          int16
}

ConditionEffect represents a confitional force feedback effect.

type ConstantEffect

type ConstantEffect struct {
	Level    int16
	Envelope Envelope
}

ConstantEffect renders constant force-feedback effects.

type Device

type Device struct {
	Inbox  chan Event // Channel exposing incoming events.
	Outbox chan Event // Channel for outgoing events.
	// contains filtered or unexported fields
}

Device represents a single device node.

func Find

func Find(devtype int) (list []*Device, err error)

Find returns a list of all attached devices, which qualify as the given device type.

func Open

func Open(node string) (dev *Device, err error)

Open opens a new device for the given node name. This can be anything listed in /dev/input/event[x].

func (*Device) AbsoluteAxes

func (d *Device) AbsoluteAxes() Bitset

AbsoluteAxes returns a bitfield indicating which absolute axes are supported by the device.

This is only applicable to devices with EvAbsolute event support.

func (*Device) AbsoluteInfo

func (d *Device) AbsoluteInfo(axis int) AbsInfo

AbsoluteInfo provides state information for one absolute axis. If you want the global state for a device, you have to call the function for each axis present on the device. See Device.AbsoluteAxes() for details on how find them.

This is only applicable to devices with EvAbsolute event support.

func (*Device) Close

func (d *Device) Close() (err error)

Close closes the underlying device node.

func (*Device) EventTypes

func (d *Device) EventTypes() Bitset

EventTypes determines the device's capabilities. It yields a bitset which can be tested against EvXXX constants to determine which types are supported.

func (*Device) ForceFeedbackCaps

func (d *Device) ForceFeedbackCaps() (int, Bitset)

ForceFeedbackCaps returns a bitset which specified the kind of Force Feedback effects supported by this device. The bits can be compared against the FFXXX constants. Additionally, it returns the number of effects this device can handle simultaneously.

This is only applicable to devices with EvForceFeedback event support.

func (*Device) Grab

func (d *Device) Grab() bool

Grab attempts to gain exclusive access to this device. This means that we are the only ones receiving events from the device; other processes will not.

This ability should be handled with care, especially when trying to lock keyboard access. If this is executed while we are running in something like X, this call will prevent X from receiving any and all keyboard events. All of them will only be sent to our own process. If we do not properly handle these key events, we may lock ourselves out of the system and a hard reset is required to restore it.

func (*Device) Id

func (d *Device) Id() Id

Id returns the device identity.

func (*Device) KeyMap

func (d *Device) KeyMap(keycode int) KeymapEntry

KeyMap fills the key mapping for the given key. E.g.: Pressing M, will input N into the input system. This allows us to rewire physical keys.

Refer to `Device.SetKeyMap()` for information on what this means.

Be aware that the KeyMap functions may not work on every keyboard. This is only applicable to devices with EvKey event support.

func (*Device) KeyState

func (d *Device) KeyState() Bitset

Keystate returns the current,global key- and button- states.

This is only applicable to devices with EvKey event support.

func (*Device) LEDState

func (d *Device) LEDState() Bitset

LEDState returns the current, global LED state.

This is only applicable to devices with EvLed event support.

func (*Device) Name

func (d *Device) Name() string

Name returns the name of the device.

func (*Device) Path

func (d *Device) Path() string

Path returns the physical path of the device. For example:

usb-00:01.2-2.1/input0

To understand what this string is showing, you need to break it down into parts. `usb` means this is a physical topology from the USB system.

`00:01.2` is the PCI bus information for the USB host controller (in this case, bus 0, slot 1, function 2).

`2.1` shows the path from the root hub to the device. In this case, the upstream hub is plugged in to the second port on the root hub, and that device is plugged in to the first port on the upstream hub.

`input0` means this is the first event interface on the device. Most devices have only one, but multimedia keyboards may present the normal keyboard on one interface and the multimedia function keys on a second interface.

func (*Device) PlayEffect

func (d *Device) PlayEffect(id int16)

PlayEffect plays a previously uploaded effect.

func (*Device) RelativeAxes

func (d *Device) RelativeAxes() Bitset

RelativeAxes returns a bitfield indicating which relative axes are supported by the device.

This is only applicable to devices with EvRelative event support.

func (*Device) Release

func (d *Device) Release() bool

Release releases a lock, previously obtained through `Device.Grab`.

func (*Device) RepeatState

func (d *Device) RepeatState() (uint, uint)

RepeatState returns the current, global repeat state. This applies only to devices which have the EvRepeat capability defined. This can be determined through `Device.EventTypes()`.

Refer to Device.SetRepeatState for an explanation on what the returned values mean.

This is only applicable to devices with EvRepeat event support.

func (*Device) Serial

func (d *Device) Serial() string

Serial returns the unique serial code for the device. Most devices do not have this and will return an empty string.

func (*Device) SetEffectAutoCenter

func (d *Device) SetEffectAutoCenter(factor int)

SetEffectAutoCenter changes the force feedback autocenter factor. The specified factor should be in the range 0-100. A value of 0 means: no autocenter.

This is only applicable to devices with EvForceFeedback event support.

func (*Device) SetEffectGain

func (d *Device) SetEffectGain(gain int)

SetEffectGain changes the force feedback gain.

Not all devices have the same effect strength. Therefore, users should set a gain factor depending on how strong they want effects to be. This setting is persistent across access to the driver.

The specified gain should be in the range 0-100. This is only applicable to devices with EvForceFeedback event support.

func (*Device) SetEffects

func (d *Device) SetEffects(list ...*Effect) bool

SetEffects sends the given list of Force Feedback effects to the device. The length of the list should not exceed the count returned from `Device.ForceFeedbackCaps()`.

After this call completes, the effect.Id field will contain the effect's id which must be used when playing or stopping the effect. It is also possible to reupload the same effect with the same id later on with new parameters. This allows us to update a running effect, without first stopping it.

This is only applicable to devices with EvForceFeedback event support.

func (*Device) SetKeyMap

func (d *Device) SetKeyMap(entry KeymapEntry) bool

SetKeyMap sets the given key to the specified mapping. E.g.: Pressing M, will input N into the input system. This allows us to rewire physical keys.

Some input drivers support variable mappings between the keys held down (which are interpreted by the keyboard scan and reported as scancodes) and the events sent to the input layer.

You can change which key is associated with each scancode using this call. The value of the scancode is the first element in the integer array (list[n][0]), and the resulting input event key number (keycode) is the second element in the array. (list[n][1]).

Be aware that the KeyMap functions may not work on every keyboard. This is only applicable to devices with EvKey event support.

func (*Device) SetRepeatState

func (d *Device) SetRepeatState(initial, subsequent uint) bool

SetRepeatState sets the global repeat state for the given device.

The values indicate (in milliseconds) the delay before the device starts repeating and the delay between subsequent repeats. This might apply to a keyboard where the user presses and holds a key.

E.g.: We see an initial character immediately, then another @initial milliseconds later and after that, once every @subsequent milliseconds, until the key is released.

This returns false if the operation failed.

This is only applicable to devices with EvRepeat event support.

func (*Device) StopEffect

func (d *Device) StopEffect(id int16)

StopEffect stops a previously uploaded effect from playing.

func (*Device) Test

func (d *Device) Test(set Bitset, values ...int) bool

Test takes a bitset and a list of constants and tests one against the other to see if the device supports a given set of properties.

It returns true only if the bitset defines all the supplied types. E.g.: To test for certain event types:

if dev.Test(dev.EventTypes(), EvKey, EvRepeat) {

To test for certain absolute axes:

if dev.Test(dev.AbsoluteAxes(), AbsX, AbsY, AbsZ) {

To test for certain relative axes:

if dev.Test(dev.RelativeAxes(), RelX, RelY, RelZ) {

func (*Device) UnsetEffects

func (d *Device) UnsetEffects(list ...*Effect) bool

UnsetEffects deletes the given effects from the device. This makes room for new effects in the device's memory. Note that this also stops the effect if it was playing.

This is only applicable to devices with EvForceFeedback event support.

func (*Device) Version

func (d *Device) Version() (int, int, int)

Version returns version information for the device driver. These being major, minor and revision numbers.

type Effect

type Effect struct {
	Type      uint16
	Id        int16
	Direction uint16
	Trigger   Trigger
	Replay    Replay
	// contains filtered or unexported fields
}

Effect describes any of the supported Force Feedback effects.

Supported effects are as follows:

  • FFConstant Renders constant force effects
  • FFPeriodic Renders periodic effects with the following waveforms:
  • FFSquare Square waveform
  • FFTriangle Triangle waveform
  • FFSine Sine waveform
  • FFSawUp Sawtooth up waveform
  • FFSawDown Sawtooth down waveform
  • FFCustom Custom waveform
  • FFRamp Renders ramp effects
  • FFSpring Simulates the presence of a spring
  • FFFriction Simulates friction
  • FFDamper Simulates damper effects
  • FFRumble Rumble effects
  • FFInertia Simulates inertia
  • FFGain Gain is adjustable
  • FFAutoCenter Autocenter is adjustable

Note: In most cases you should use FFPeriodic instead of FFRumble. All devices that support FFRumble support FFPeriodic (square, triangle, sine) and the other way around.

Note: The exact layout of FFCustom waveforms is undefined for the time being as no driver supports it yet.

Note: All duration values are expressed in milliseconds. Values above 32767 ms (0x7fff) should not be used and have unspecified results.

func (*Effect) Data

func (e *Effect) Data() interface{}

Data returns the event data structure as a concrete type. Its type depends on the value of Effect.Type and can be any of:

FFConstant -> ConstantEffect
FFPeriodic -> PeriodicEffect
FFRamp     -> RampEffect
FFRumble   -> RumbleEffect
FFSpring   -> [2]ConditionEffect
FFDamper   -> [2]ConditionEffect

This returns nil if the type was not recognized.

func (*Effect) SetData

func (e *Effect) SetData(v interface{})

SetData sets the event data structure.

type Envelope

type Envelope struct {
	AttackLength uint16
	AttackLevel  uint16
	FadeLength   uint16
	FadeLevel    uint16
}

type Event

type Event struct {
	Time  syscall.Timeval
	Type  uint16
	Code  uint16
	Value int32
}

Event represents a generic input event.

type Id

type Id struct {
	BusType uint16
	Vendor  uint16
	Product uint16
	Version uint16
}

Id represents the device identity.

The bus type is the only field that contains accurate data. It can be compared to the BusXXX constants. The vendor, product and version fields are bus type-specific information relating to the identity of the device. Modern devices (typically using PCI or USB) do have information that can be used, but legacy devices (such as serial mice, PS/2 keyboards and game ports on ISA sound cards) do not. These numbers therefore are not meaningful for some values of bus type.

type KeymapEntry

type KeymapEntry struct {
	Flags    uint8     // They specify how the kernel should handle a keymap request.
	Len      uint8     // Length of the scancode that resides in Scancode buffer.
	Index    uint16    // Index in the keymap, may be used instead of scancode
	Keycode  uint32    // Key code assigned to this scancode
	Scancode [32]uint8 // Scancode represented in machine-endian form.
}

KeymapEntry is used to retrieve and modify keymap data. Users have option of performing lookup either by @scancode itself or by @index in a keymap entry. Device.KeyMap() will also return scancode or index (depending on which element was used to perform lookup).

type PeriodicEffect

type PeriodicEffect struct {
	Waveform  uint16
	Period    uint16
	Magnitude int16
	Offset    int16
	Phase     uint16
	Envelope  Envelope
	// contains filtered or unexported fields
}

PeriodicEffect renders periodic force-feedback effects with the following waveforms: Square, Triangle, Sine, Sawtooth or a custom waveform.

func (*PeriodicEffect) Data

func (e *PeriodicEffect) Data() []int16

Data returns custom waveform information. This comes in the form of a signed 16-bit slice.

The exact layout of a custom waveform is undefined for the time being as no driver supports it yet.

func (*PeriodicEffect) SetData

func (e *PeriodicEffect) SetData(v []int16)

SetData sets custom waveform information.

The exact layout of a custom waveform is undefined for the time being as no driver supports it yet.

type RampEffect

type RampEffect struct {
	StartLevel int16
	EndLevel   int16
	Envelope   Envelope
}

RampEffect renders ramp force-feedback effects.

type Replay

type Replay struct {
	Length uint16
	Delay  uint16
}

type RumbleEffect

type RumbleEffect struct {
	StrongMagnitude uint16
	WeakMagnitude   uint16
}

The rumble effect is the most basic effect, it lets the device vibrate. The API contains support for two motors, a strong one and a weak one, which can be controlled independently.

type Trigger

type Trigger struct {
	Button   uint16
	Interval uint16
}

type Word

type Word uint64

A word is part of a bitset.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL