Documentation
¶
Overview ¶
Package uinput is a pure go package that provides access to the userland input device driver uinput on linux systems. Virtual keyboard devices as well as virtual mouse input devices may be created using this package. The keycodes and other event definitions, that are available and can be used to trigger input events, are part of this package ("Key1" for number 1, for example).
In order to use the virtual keyboard, you will need to follow these three steps:
Initialize the device Example: vk, err := CreateKeyboard("/dev/uinput", "Virtual Keyboard")
Send Button events to the device Example (print a single D): err = vk.KeyPress(uinput.KeyD)
Example (keep moving right by holding down right arrow key): err = vk.KeyDown(uinput.KeyRight)
Example (stop moving right by releasing the right arrow key): err = vk.KeyUp(uinput.KeyRight)
Close the device Example: err = vk.Close()
A virtual mouse input device is just as easy to create and use:
Initialize the device: Example: vm, err := CreateMouse("/dev/uinput", "DangerMouse")
Move the cursor around and issue click events Example (move mouse right): err = vm.MoveRight(42)
Example (move mouse left): err = vm.MoveLeft(42)
Example (move mouse up): err = vm.MoveUp(42)
Example (move mouse down): err = vm.MoveDown(42)
Example (trigger a left click): err = vm.LeftClick()
Example (trigger a right click): err = vm.RightClick()
Close the device Example: err = vm.Close()
If you'd like to use absolute input events (move the cursor to specific positions on screen), use the touch pad. Note that you'll need to specify the size of the screen area you want to use when you initialize the device. Here are a few examples of how to use the virtual touch pad:
Initialize the device: Example: vt, err := CreateTouchPad("/dev/uinput", "DontTouchThis", 0, 1024, 0, 768)
Move the cursor around and issue click events Example (move cursor to the top left corner of the screen): err = vt.MoveTo(0, 0)
Example (move cursor to the position x: 100, y: 250): err = vt.MoveTo(100, 250)
Example (trigger a left click): err = vt.LeftClick()
Example (trigger a right click): err = vt.RightClick()
Close the device Example: err = vt.Close()
Index ¶
Constants ¶
const ( KeyEsc = 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 /*ScSystemPowerDown*/ KeyKpequal = 117 KeyKpplusminus = 118 KeyPause = 119 KeyScale = 120 /*AlCompizScale(Expose)*/ KeyKpcomma = 121 KeyHangeul = 122 KeyHanja = 123 KeyYen = 124 KeyLeftmeta = 125 KeyRightmeta = 126 KeyCompose = 127 KeyStop = 128 /*AcStop*/ KeyAgain = 129 KeyProps = 130 /*AcProperties*/ KeyUndo = 131 /*AcUndo*/ KeyFront = 132 KeyCopy = 133 /*AcCopy*/ KeyOpen = 134 /*AcOpen*/ KeyPaste = 135 /*AcPaste*/ KeyFind = 136 /*AcSearch*/ KeyCut = 137 /*AcCut*/ KeyHelp = 138 /*AlIntegratedHelpCenter*/ KeyMenu = 139 /*Menu(ShowMenu)*/ KeyCalc = 140 /*AlCalculator*/ KeySetup = 141 KeySleep = 142 /*ScSystemSleep*/ KeyWakeup = 143 /*SystemWakeUp*/ KeyFile = 144 /*AlLocalMachineBrowser*/ KeySendfile = 145 KeyDeletefile = 146 KeyXfer = 147 KeyProg1 = 148 KeyProg2 = 149 KeyWww = 150 /*AlInternetBrowser*/ KeyMsdos = 151 KeyCoffee = 152 /*AlTerminalLock/Screensaver*/ KeyDirection = 153 KeyCyclewindows = 154 KeyMail = 155 KeyBookmarks = 156 /*AcBookmarks*/ KeyComputer = 157 KeyBack = 158 /*AcBack*/ KeyForward = 159 /*AcForward*/ KeyClosecd = 160 KeyEjectcd = 161 KeyEjectclosecd = 162 KeyNextsong = 163 KeyPlaypause = 164 KeyPrevioussong = 165 KeyStopcd = 166 KeyRecord = 167 KeyRewind = 168 KeyPhone = 169 /*MediaSelectTelephone*/ KeyIso = 170 KeyConfig = 171 /*AlConsumerControlConfiguration*/ KeyHomepage = 172 /*AcHome*/ KeyRefresh = 173 /*AcRefresh*/ KeyExit = 174 /*AcExit*/ KeyMove = 175 KeyEdit = 176 KeyScrollup = 177 KeyScrolldown = 178 KeyKpleftparen = 179 KeyKprightparen = 180 KeyNew = 181 /*AcNew*/ KeyRedo = 182 /*AcRedo/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 /*AlDashboard*/ KeySuspend = 205 KeyClose = 206 /*AcClose*/ KeyPlay = 207 KeyFastforward = 208 KeyBassboost = 209 KeyPrint = 210 /*AcPrint*/ KeyHp = 211 KeyCamera = 212 KeySound = 213 KeyQuestion = 214 KeyEmail = 215 KeyChat = 216 KeySearch = 217 KeyConnect = 218 KeyFinance = 219 /*AlCheckbook/Finance*/ KeySport = 220 KeyShop = 221 KeyAlterase = 222 KeyCancel = 223 /*AcCancel*/ KeyBrightnessdown = 224 KeyBrightnessup = 225 KeyMedia = 226 KeySwitchvideomode = 227 /*CycleBetweenAvailableVideo */ KeyKbdillumtoggle = 228 KeyKbdillumdown = 229 KeyKbdillumup = 230 KeySend = 231 /*AcSend*/ KeyReply = 232 /*AcReply*/ KeyForwardmail = 233 /*AcForwardMsg*/ KeySave = 234 /*AcSave*/ KeyDocuments = 235 KeyBattery = 236 KeyBluetooth = 237 KeyWlan = 238 KeyUwb = 239 KeyUnknown = 240 KeyVideoNext = 241 /*DriveNextVideoSource*/ KeyVideoPrev = 242 /*DrivePreviousVideoSource*/ KeyBrightnessCycle = 243 /*BrightnessUp,AfterMaxIsMin*/ KeyBrightnessZero = 244 /*BrightnessOff,UseAmbient*/ KeyDisplayOff = 245 /*DisplayDeviceToOffState*/ KeyWimax = 246 KeyRfkill = 247 /*KeyThatControlsAllRadios*/ KeyMicmute = 248 /*Mute/UnmuteTheMicrophone*/ ButtonGamepad = 0x130 ButtonSouth = 0x130 // A / X ButtonEast = 0x131 // X / Square ButtonNorth = 0x133 // Y / Triangle ButtonWest = 0x134 // B / Circle ButtonBumperLeft = 0x136 // L1 ButtonBumperRight = 0x137 // R1 ButtonTriggerLeft = 0x138 // L2 ButtonTriggerRight = 0x139 // R2 ButtonThumbLeft = 0x13d // L3 ButtonThumbRight = 0x13e // R3 ButtonSelect = 0x13a ButtonStart = 0x13b ButtonDpadUp = 0x220 ButtonDpadDown = 0x221 ButtonDpadLeft = 0x222 ButtonDpadRight = 0x223 ButtonMode = 0x13c // This is the special button that usually bears the Xbox or Playstation logo // Used to Declare force-feedback Capabilities FFRumble = 0x50 FFPeriodic = 0x51 FFConstant = 0x52 FFSpring = 0x53 FFFriction = 0x54 FFDamper = 0x55 FFInertia = 0x56 FFRamp = 0x57 )
the constants that are defined here relate 1:1 to the constants defined in input.h and represent actual key codes that can be triggered as key events
const MaximumAxisValue = 32767
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FFConditionEffect ¶
type FFConstantEffect ¶
type FFConstantEffect struct { Level int16 Envelope FFEnvelope }
type FFEffect ¶
type FFEffect struct { Type uint16 ID int16 Direction uint16 Trigger FFTrigger Replay FFReplay // contains filtered or unexported fields }
to access the values in U use the function Rumble() Periodic() etc check FFEffect.Type to call the correct function calling a function that doesn't match the type is undefined
func (*FFEffect) Condition ¶
func (ff *FFEffect) Condition() [2]FFConditionEffect
func (*FFEffect) Constant ¶
func (ff *FFEffect) Constant() FFConstantEffect
func (*FFEffect) Periodic ¶
func (ff *FFEffect) Periodic() FFPeriodicEffect
func (*FFEffect) Ramp ¶
func (ff *FFEffect) Ramp() FFRampEffect
func (*FFEffect) Rumble ¶
func (ff *FFEffect) Rumble() FFRumbleEffect
type FFEnvelope ¶
type FFPeriodicEffect ¶
type FFRampEffect ¶
type FFRampEffect struct { StartLevel int16 EndLevel int16 Envelope FFEnvelope }
type FFRumbleEffect ¶
type Gamepad ¶
type Gamepad interface { // ButtonPress will cause the button to be pressed and immediately released. ButtonPress(key int) error // ButtonDown will send a button-press event to an existing gamepad device. // The key can be any of the predefined keycodes from keycodes.go. // Note that the key will be "held down" until "KeyUp" is called. ButtonDown(key int) error // ButtonUp will send a button-release event to an existing gamepad device. // The key can be any of the predefined keycodes from keycodes.go. ButtonUp(key int) error // LeftStickMoveX performs a movement of the left stick along the x-axis LeftStickMoveX(value float32) error // LeftStickMoveY performs a movement of the left stick along the y-axis LeftStickMoveY(value float32) error // RightStickMoveX performs a movement of the right stick along the x-axis RightStickMoveX(value float32) error // RightStickMoveY performs a movement of the right stick along the y-axis RightStickMoveY(value float32) error // LeftStickMove moves the left stick along the x and y-axis LeftStickMove(x, y float32) error // RightStickMove moves the right stick along the x and y-axis RightStickMove(x, y float32) error // HatPress will issue a hat-press event in the given direction HatPress(direction HatDirection) error // HatRelease will issue a hat-release event in the given direction HatRelease(direction HatDirection) error // LeftTriggerForce performs a trigger-axis-z event with a given force LeftTriggerForce(value float32) error // RightTriggerForce performs a trigger-axis-rz event with a given force RightTriggerForce(value float32) error io.Closer }
Gamepad is a hybrid key / absolute change event output device. It used to enable a program to simulate gamepad input events.
type GamepadWithRumble ¶
type GamepadWithRumble interface { Gamepad // Call this function periodically to check for force-feedback. // the callback return will be placed into upload.ReturnValue // it is not an guarante that the callback will be called ForceFeedbackCallback(callback func(upload *UInputFFUpload, erase *UInputFFErase) int32) error }
func CreateGamepadWithRumble ¶
func CreateGamepadWithRumble(path string, name []byte, vendor uint16, product uint16, effectsMax uint32) (GamepadWithRumble, error)
CreateGamepadWithRumble will create a new gamepad using the given uinput device path of the uinput device, and will rumble support. Using a gamepad with rumble requires calling ForceFeedbackCallback periodically
type HatDirection ¶
type HatDirection int
HatDirection specifies the direction of hat movement
const ( HatUp HatDirection = iota + 1 HatDown HatLeft HatRight )