Jump to content

[LE] Input.TapKey(1): get it to work consistently for gamepads as well


Recommended Posts

Hello,

 

I'm making a feature (namely this), that requires the

Input.TapKey(1)  ; fake Esc press

code to close down a UI from a script.

 

While this seems to work fine for keyboard+mouse (at least, it works for me), so far nobody I've talked to, who uses a controller/gamepad/, was able to get it working. When the UI is supposed be closed by this, nothing happens.

 

I'm assuming that the problem lies in the different dxscancodes of the controlmap.txt for keyboard vs gamepad.

 

On the wiki it says:

Supported GamePad buttons:
0x10A 266 DPAD_UP
0x10B 267 DPAD_DOWN
0x10C 268 DPAD_LEFT
0x10D 269 DPAD_RIGHT
0x10E 270 START
0x10F 271 BACK
0x110 272 LEFT_THUMB
0x111 273 RIGHT_THUMB
0x112 274 LEFT_SHOULDER
0x113 275 RIGHT_SHOULDER
0x114 276 A
0x115 277 B
0x116 278 X
0x117 279 Y
0x118 280 LT
0x119 281 RT

One of the controller users said that the equivalent of Esc would be the B button.

So I tried to modify my script like this:

if(Game.UsingGamePad())
    Input.TapKey(277)
else
    Input.TapKey(1)
endif

I'm afraid that did nothing, still nothing happens for controller users.

I did some printouts:

- Game.UsingGamePad() seems to work correctly

- I also tried to print out Input.GetMappedKey("Pause"), which returned:

- '1' for keyboard, as expected

- '-1' aka 'unmapped' for 1 person using a controller

 

So I'm guessing that this is where the problem lies, for controllers these dx keycodes are just... somehow different.

 

Does someone know what's going on? What key code should be pressed in case of a controller to achieve the effect of pressing Esc on a keyboard?

 

 

 

 

EDIT:

Figured this:

Game.DisablePlayerControls(abMovement = false, abFighting = false, abCamSwitch = false, abLooking = false, abSneaking = false, abMenu = true, abActivate = false, abJournalTabs = false)
Utility.Wait(0.1)
Game.EnablePlayerControls(abMovement = false, abFighting = false, abCamSwitch = false, abLooking = false, abSneaking = false, abMenu = true, abActivate = false, abJournalTabs = false)

This seems to work as well, at least in the case of a keyboard. It's independent of the input script, so I think this will also work for gamepads.

Link to comment
Share on other sites

On a controller B is the "tween menu" which corresponds to Tab on the keyboard. Esc which brings up the "start menu" would be the Start button (the one with the three lines on it) at least for an Xbox controller.

 

That said, I have never tried to use TapKey with a controller. I have used OnKeyDown to listen for button presses from a controller.

 

Do you have a controller? Can you test to see what happens if you "tap" the keyboard key while in controller mode?

Link to comment
Share on other sites

No... that's the problem, I don't have a controller. I can't test anything related to it, I can only guess, and ask other people to test.

 

A friend with a controller with a modded controlmap.txt has found this:

The feature itself doesn't work, so Input.TapKey(1) does nothing.

 

Apparently, GetMappedKey("Pause") returns -1 with a controller, so it's completely unmapped towards the Input script. (Returns 1 correctly for keyboard for me).

 

We also tried to "scan" the keycode of the B button, see what a script sees when it's pressed. This was done with GetNthKeyPressed in a scanning wait-for-input while loop:

 

int keycode = -1
while(keycode == -1)
    keycode = Input.GetNthKeyPressed(0)
    ; with some added counter to stop the loop after a good while if nothing is happening, so if keycode is staying -1 and not detecting what is being pressed
endwhile
if(keycode != -1)
    Debug.Notification("Detected pressed key: "+keycode)
else
    Debug.Notification("No input detected, key is unmapped, keycode stayed at -1")
endif

 

Keycode stays -1 for B, and also for A (another test). He didn't test the start button.

I carried out the same scanning test, and all keys returned the correct keycode that's shown for them on the wiki, so the test itself works on keyboard. (I tried Esc, tab, i, w,a,s,d, etc.). That leads me to assume that the Input script simply cannot handle a controller.

 

So I kinda gave up.

I instead found what I added in the edit of the OP: another way to close down menus, that doesn't rely on the Input script.

A downside is that this also exits the player from the inventory view (whereas in my context I just want to close down a book menu, but not the entire inventory menu).

It would be cool to find a way to bring the inventory menu back up automatically after this forces it to close.

Input.TapKey(<code for i>).... forget it, it won't work :D (that's why I also asked to check if the A button works - it doesn't.)

 

Actor.OpenInventory(bool forced) is apparently not made for this, that's some sort of pickpocketing menu opener. Trying Player.OpenInventory(true) opens a weird pickpocket from self to self menu. (and opens nothing if the forced parameter is false.)

 

I don't know any other way to open the player inventory via script.

 

So for now, for my context, I perform the check with Game.UsingGamePad(), if false, then I retain the old (and best) way of using Input.TapKey(1), and if true, then it'll use the other way in the edit of the OP, and gamepad users will thus have to live with the compromise that if they wanted to stay in inventory view, they have to open it back manually.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...