kniffen / TruckSim-Telemetry

Telemetry data from the scs-sdk-plugin
MIT License
79 stars 12 forks source link

Is possible to input commands to the game? #17

Closed brunogirome closed 1 year ago

brunogirome commented 1 year ago

Hello, hope you guys are fine.

According to SCS Telemetry page, there's an option to named "Input API", which suggest, I suppose, the possibility to input some command via de API.

In the current documentation, I don't notice anything about these functions.

It's any chance to get into this JavaScript library?

jormc commented 1 year ago

Hello,

No, it is not possible, and it would be a great option...

I did my communication with the host through an express server, which executes keyboard commands when the game is running, and then emulates keyboard input...

On the client side, I have an angular application that connects to this express server and consumes the telemetry data, as well as how it sends the commands via api.

If there was a better option, I would love to know it.

Best regards,

Jordi MC

brunogirome commented 1 year ago

Hello @jormc , thanks for the answer!

Which package are you using to give the keyboard commands? I'm trying with robotjs, but it's only working the first time I give the command

jormc commented 1 year ago

Hi @brunogirome ,

Sure! Try this, it works for me: https://www.npmjs.com/package/commander

Tell me if it was a solution for you :-)

brunogirome commented 1 year ago

Again, thanks for the help agaian, @jormc ! But I got my solution using nut-js.

Also, first I was having trouble with spamming, but it was some express limitation, so I changed it to socket.io and now it's work pretty smooth.

My code is something like:

Backend:

import { keyboard } from '@nut-tree/nut-js';

io.on('connection', socket => {
  socket.on('ingame_command', key => {
    console.log(`${key} pressed`);

    keyboard.type(key);
  });
});

And frontend:

 socket.emit('ingame_command', 'F');

Hope it's help someone in the future. 🙂

jormc commented 1 year ago

Hi there @brunogirome ,

Exactly! That was my solution, I make all my communication via socketio, and on the server, put key commands via commander, but nut was another possibility for me.

Thanks for your feedback! :-)

kniffen commented 1 year ago

@jormc @brunogirome Thanks you both for the information you have provided here. I have been looking for a solution like this for another project for a while, I hope others can find it useful as well.

However I'm not going to add this feature to trucksim-telemetry, as its main goal is just to provide the data from the plugin in nodejs.

AltriusRS commented 1 year ago

If you need any alternative suggestions for NodeJS based desktop automation stuff, Robot.JS is really good