mouse and keyboard emulator via gamepad utility with sdl2

User projects written in or related to FreeBASIC.
Post Reply
thrive4
Posts: 72
Joined: Jun 25, 2021 15:32

mouse and keyboard emulator via gamepad utility with sdl2

Post by thrive4 »

description
basic mouse and keyboard emulator via gamepad utility
(configurable via a .mke file see example below)
written in freebasic and sdl2
a specific key can be used for timed actions example
settimerduration = 2.5
settimeron = btback

usage
gamepad2mkb.exe "path to file"
if no file is specified then defaults to no emulation

or specify a path via conf\conf.ini
[gamepad map]
' location mke
paddefinition = conf<filename>.mke

source (and more info):
https://github.com/thrive4/util.fb.gamepad2mkb
release (32bit windows):
https://github.com/thrive4/util.fb.gamepad2mkb/releases

requirements
sdl2 (32bit) v2.24.2.0
https://github.com/libsdl-org/SDL/releases

gottcha's:
keybd_event seems to be allergic to directional keys... use sendinput
sendinput seems to be allergic to 'escape' use keybd_event...
Probably due to ascii 27, not sure.

example .mke structure
[general]
mapversion = 1.0
settimerduration = 2.5
settimeron = btback
deadzone = 0.4

[joystick01]
lstick_left_2key =
lstick_right_2key =
lstick_up_2key =
lstick_down_2key =
rstick_left_2key =
rstick_right_2key =
rstick_up_2key =
rstick_down_2key =
lstick2mouse = true
rstick2mouse = true
SDL_CONTROLLER_BUTTON_A = mouse left
SDL_CONTROLLER_BUTTON_B = key h
SDL_CONTROLLER_BUTTON_X = mouse right
SDL_CONTROLLER_BUTTON_Y = key i
SDL_CONTROLLER_BUTTON_BACK = key return
SDL_CONTROLLER_BUTTON_GUIDE =
SDL_CONTROLLER_BUTTON_START = key escape
SDL_CONTROLLER_BUTTON_LEFTSTICK =
SDL_CONTROLLER_BUTTON_RIGHTSTICK =
SDL_CONTROLLER_BUTTON_LEFTSHOULDER =
SDL_CONTROLLER_BUTTON_RIGHTSHOULDER =
SDL_CONTROLLER_AXIS_TRIGGERLEFT = mouse right
SDL_CONTROLLER_AXIS_TRIGGERRIGHT = mouse left
SDL_CONTROLLER_BUTTON_DPAD_UP = key up
SDL_CONTROLLER_BUTTON_DPAD_DOWN = key down
SDL_CONTROLLER_BUTTON_DPAD_LEFT = key left
SDL_CONTROLLER_BUTTON_DPAD_RIGHT = key right

special thanks
sero - https://freebasic.net/forum/viewtopic.php?t=29164
MichaelW - viewtopic.php?p=38761&hilit=SendInput#p38761
thrive4
Posts: 72
Joined: Jun 25, 2021 15:32

Re: mouse and keyboard emulator via gamepad utility with sdl2

Post by thrive4 »

Quite a number of updates thought I would pass it on.

update v1.2 04/01/2024
- refactored most gamepad input code for better handling
. added independent acceleration per stick improved mouse
. click with left and right trigers etc.
- tweaked .mke(s)
- corrected screensize factor acceleration
. now polls while game is running
- added modifier deadzone to thumb axis acceleration
- added shift, ctrl and function keys 1 to 5 as configurable keys
- corrected freefile variable type to long
. integer causes issues when opening multiple
. file in succession
- trimmed utilfile.bas
- updated sdl2.dll from 2.26.5.0 to 2.28.5.0
- added locale nl and updated help.ini
- phased out small sdl window
- getuilabelvalue implemented full automatic spacing
- expanded localization added dutch
. todo translated string size and ui placement need work
- note with the newer version of sdl
. ram / handles and threads usage has been reduced

See:
https://github.com/thrive4/util.fb.gamepad2mkb

Tips:
ghetto vectors (for a more radial deadzone detection)

Code: Select all

    dim vecr as single = axis2mouse.mouseaccrx * axis2mouse.mouseaccrx + axis2mouse.mouseaccry * axis2mouse.mouseaccry
    dim vecl as single = axis2mouse.mouseacclx * axis2mouse.mouseacclx + axis2mouse.mouseaccly * axis2mouse.mouseaccly
More info on this see:
https://github.com/Minimuino/thumbstick-deadzones
Post Reply