steamworks.js icon indicating copy to clipboard operation
steamworks.js copied to clipboard

Implement the rest of the iSteamInput API

Open codingMASTER398 opened this issue 1 year ago • 6 comments

Steamworks-rs supports some functions that I'd really like, such as "get_glyph_for_action_origin", "get_motion_data", "show_binding_panel", "run_frame", etc. They're not in steamworks.js though, and that's a shame. I wasted about 3 days trying to get steamworks-node to work, to no avail either.

I'll try and implement them myself, but I know next to nothing about Rust. It'd be great to have official support for this.

codingMASTER398 avatar Sep 16 '24 04:09 codingMASTER398

+1, I'd also be very interested in GetDigitalActionHandle and GetAnalogActionHandle, since as I understand it the respective funcitons without Handle expect bigints that can only be queried with those.

edit: nvm, I figured it out.

const client = steamworks.init(<appID>);

client.input.init();

// query the IDs (bigints) the steamworks sdk assigns to your game actions
// action strings are the keys of the actions defined in <Steam Install Path>\controller_config\game_actions_<appID>.vdf
const jump = client.input.getDigitalAction('jump');
const move = client.input.getAnalogAction('move');

// replace setInterval with Ipc polls or query them directly in your requestAnimationFrame-Loop if you enabled native modules in renderer thread
setInterval(() => {
    client.input.getControllers().forEach((controller) => {
        // query the input state of your actions using the previously queried action IDs
        console.log(controller.isDigitalActionPressed(jump)); // true | false
        console.log(controller.getAnalogActionVector(move)); // {x: int, y: int}
    });
}, 1000);

tomm1996 avatar Nov 03 '24 02:11 tomm1996

edit: nvm, I figured it out. // query the IDs (bigints) the steamworks sdk assigns to your game actions // action strings are the keys of the actions defined in <Steam Install Path>\controller_config\game_actions_<appID>.vdf const jump = client.input.getDigitalAction('jump'); const move = client.input.getAnalogAction('move');

I'm running into this right now and I can get any big_int returned. I try to use the "controller_generic_gamepad_joystick" Steam offers, but the declaration seems so different from the doc, I tried any key word and none returned anything.

Also you don't do getActionSet before ??

Any help would be amazing.

Thanks

Inateno avatar Feb 11 '25 10:02 Inateno

I'm running into this right now and I can get any big_int returned. I try to use the "controller_generic_gamepad_joystick" Steam offers, but the declaration seems so different from the doc, I tried any key word and none returned anything.

Also you don't do getActionSet before ??

Any help would be amazing.

Thanks

NVM after hours of lurking and testing I finally managed to make it works, so for the people who would pass over there:

  • the first VDF file you have to do is a "dummy file" that only describe actions separated between several layers (modes)
  • then, by following the steam doc (https://partner.steamgames.com/doc/features/steam_controller/getting_started_for_devs this one) you run the Gamepad configurator editor through the overlay or the big picture (here is the weird point I was blocking at, you must choose "templates" and there is an empty one, which is your dummy VDF
  • then you configure each button/trigger whatever to the "inputs names"
  • and finally you can use this in your code (just follow the Steam doc until 3)

Also some other stuff I noticed:

  • you can't use activateActionSet for different set at the same time, so you must create some kind of layers for your game if you have different inputs name like me, but if you just use "left/right" for game and menu, only one is fine
  • to detect if the gamepad was disconnected you must compare controllers.length
  • you can, with the Steam Inputs configurator, bind several "action names" on the same button! Pretty much useful if you use different input names in the game that are linked on the same button.

In the end I just created a big json object which declare all my sets and "types" so I can instantiate all variable/getter/setter easily while the game is running:

export const inputSetList: {
  [setName: string]: { [inputName: string]: 'digital' | 'analog' };
} = {
  InGameControls: {
    jump: 'digital',
   move: 'analog',
  } as const,

  MenuControls: {
    menuUp: 'digital',
    menuDown: 'digital',
    menuLeft: 'digital',
    menuRight: 'digital',
  } as const
} as const;```

By doing so you can just make a loop to generate all the "getDigitalAction" or "isDigitalActionPressed" (etc).

Hope this will be useful for anyone in the future.

Inateno avatar Feb 11 '25 17:02 Inateno

I still can't grab button ID to check if is pressed. WHat I did:

const aButtonHandle = client.input.getDigitalAction("Button_A") client.input.init();

now in update function I'm checking if pressed:

const controllers = client.input.getControllers(); if (controllers.length > 0) { const controller = controllers[0];

if (controller.isDigitalActionPressed(aButtonHandle)) { console.log("A button pressed!");

}

and the problem is that aButtonHandle return 'On' instead of btn code. I was trying everything with no luck :/

Amiga4ever avatar Apr 25 '25 10:04 Amiga4ever

I've implemented a few functions like what I described in my first message on this thread with some help from AI. I'll look into making a PR to introduce get_glyph_for_action_origin, show_binding_panel, and run_frame.

codingMASTER398 avatar Apr 30 '25 02:04 codingMASTER398

I have added too including extra node function like get Pressed but I can't create action like Fire or Jump so still can't track what was pressed. Can't bid in controller layout in Steam as get Digital is not there or even my glyph sets.

Amiga4ever avatar Apr 30 '25 05:04 Amiga4ever