based from this thread:https://www.glbasic.com/forum/index.php?topic=11565.0Im have choosen to update and reimplement GameInput to v2.0 beta. In this version the remapping has been totally rewrote and is now supporting gamepads as well keyboards. The formatting of codes is now based on a sdl database, but also added to possible to remap keyboard as well.
to implement to your game, you can do something like this: // top of the code should have those defines:
?IFDEF WIN64
?DEFINE WIN32
?ENDIF
?IFDEF WIN32
?DEFINE DESKTOP
?ENDIF
// start of the code somewhere under loading.
LOCAL SaveFile$=PLATFORMINFO$("DOCUMENTS")+"/Yourgame/Yourgame_AutoSave.ini" // should been APPDATA on other platforms.
IF STEAMDECK=1 // if you want to do that, howover users can quit remapping by mouse button now (you could get stuck).
GameInput.init(SaveController$, 1) // the first two devices should not been possible to been remapped on steamdeck.
ELSE
GameInput.init(SaveController$, -1) // if you dont want possible to remap keyboard, set it to 0.
ENDIF
// Somewhere in the game input code.
// actuelley does nothing now on Windows, but only on Android.
LOCAL profilechanged=GameInput.update()
IF GameInput.Remap_IsRemapping()=1 // the function is doing remapping, dont do any game code
LOCAL result=GameInput.Remap_ScanCode() // return a sound/visual effect.
IF result=1 THEN SoundPlay("selectlevel")
IF result=2 THEN SoundPlay("confirmlevel")
RETURN
ENDIF
// polling input from the api (incude keyboard) example. far from all games should do this.
IF ISPAUSE OR S_Status$<>"play"
GameInput.EnableKeyboard(TRUE)
ELSE
GameInput.EnableKeyboard(FALSE) // in some cases, you dont want keyboard remapped ingame.
ENDIF
// This is something like that when you want to poll a joystick. In PowerUp Elevation, wbich
// im toke this snippet from, here all sticks controls the bird (include the right one).
LOCAL K1, K2, K3, K4, KJ
LOCAL Players=GameInput.GetNumberOfPlayers()
GameInput.SetDeadZone(0, 0.6) // analoge as digital with 0.6 as deadzone.
FOR i=0 TO Players-1
//IF GameInput.GetControllerName$(i)<>""
IF Players>0 // could been 0 on Android, but allways a least 1 on Windows throught as first player is on keyboard.
KL=KL+GameInput.Left(i)+GameInput.LeftStick_Left(i)+GameInput.RightStick_Left(i); IF KL>1 THEN KL=1
KR=KR+GameInput.Right(i)+GameInput.LeftStick_Right(i)+GameInput.RightStick_Right(i); IF KR>1 THEN KR=1
KU=KU+GameInput.Up(i)+GameInput.LeftStick_Up(i)+GameInput.RightStick_Up(i); IF KU>1 THEN KU=1
KD=KD+GameInput.Down(i)+GameInput.LeftStick_Down(i)+GameInput.RightStick_Down(i); IF KD=1 THEN KD=1
IF GameInput.ActionButton("A", i) OR GameInput.ActionButton("B", i) THEN KJ=1
IF GameInput.ActionButton("X", i) OR GameInput.ActionButton("Y", i) THEN KJ=1
IF GameInput.LeftTrigger(i) OR GameInput.ActionButton("RB", i) THEN KJ=1
IF GameInput.RightTrigger(i)=1 OR GameInput.ActionButton("LB", i) THEN TURNED=1
LOCAL SE=GameInput.ActionButton("select", i); // AB cab been swapped on some controllers
LOCAL PA=GameInput.ActionButton("parent", i); // AB cab been swapped on some controllers
ENDIF
NEXT
// somewhere in the menu to start the remap
// First argument, is if you want keyboard remapped or not.
IF OPTIONSELECTNAME$="remap"
// this is a full remap for a game controller, but only required buttons for keyboard.
// if a game controller dont have all buttons, the user will escape.
// if you dont want a full remap for a controller, you can remove those you dont uses.
GameInput.Remap_Start(0,"back:back/pause|*,start:start|*,leftx:Left Stick|Movement,a:Face Bottom|Jump,b:Face Right|Turn,x:Face Left|*,y:Face Up|*,leftshoulder:Back Left Top|*,rightshoulder:Back Right Top|*,LeftTrigger:Back Left Bottom|*,RightTrigger:Back Right Bottom|*,dpdown:Dpad Down|*,dpright:Dpad Right|*,dpup:DPad Up|*,dpleft:DPad Left|*,rightx:Right Stick|*,leftstick:Left Stick|*,rightstick:Right Stick|*")
ENDIF
// somewhere to print, when under remapping (allways max 3 lines)
// also escape or back button will allways quit remapping with no save.
IF GameInput.Remap_IsRemapping()=1
LOCAL line$=GameInput.Remap_GetText$(1)
BMFont.DrawText(line$, 0, PY+PH+SCALING*70, SIN(FADING*90)*1, SIN(FADING*90)*0.5*2, 0, -1, -2)
line$=GameInput.Remap_GetText$(2)
IF line$<>"" THEN BMFont.DrawText(line$, 0, PY+PH+SCALING*75, SIN(FADING*90)*1, SIN(FADING*90)*0.5*2, 0, -1, -2)
line$=GameInput.Remap_GetText$(3)
IF line$<>"" THEN BMFont.DrawText(line$, 0, PY+PH+SCALING*80, SIN(FADING*90)*1, SIN(FADING*90)*0.5*2, 0, -1, -2)
RETURN
ENDIF
this code is only tested on Windows, while the code for Android is there, im have nowhere tested it at all. Its might or might not work, or not compile at all. No idea. Im have still yet to update Android Studio, if im want to do that.
PS. PowerUp Elevation has been updated on steam, which uses this api (that game became test game).