You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1 KiB
Lua

local fn = ...
local input = require("lib.input")
local uinput = require("lib.uinput")
local poll = require("lib.helper.posix_io").poll_read
local inp = input(fn)
local ui = uinput()
ui:copy_caps(inp)
ui:setup{
-- id=inp.device_id,
-- some apps (like wine) doesn't like if you have multiple devices with the
-- same id, in that case fake something here:
id={bustype="BLUETOOTH", vendor=1, product=2},
name="Virtual gamepad",
ff_effects_max=inp.ff_count
}
-- Assumes DS4 limits
ui:abs_setup("Z", {minimum=-255,maximum=255})
ui:abs_setup("RZ", {minimum=-255,maximum=255})
ui:create()
print("created", ui.sysname)
local kbd = uinput()
kbd:add_keyboard_caps(true)
kbd:setup{id={bustype="USB", vendor=1, product=2}, name="virtual kbd"}
kbd:create()
inp:grab() -- ! DANGER
local to_poll = { inp, ui }
local ui_ff = ui:gen_ff_forwarder(inp)
while true do
local rdy = poll(to_poll)
if rdy[inp] then
local rd = inp:read()
if rd.type == "KEY" and rd.code == "BTN_MODE" then
rd.code = "KEY_ESC"
kbd:write(rd)
kbd:write{type="SYN", code="REPORT"}
else
ui:write(rd)
end
end
if rdy[ui] then ui_ff() end
end