Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyboard not working in games #62

Open
philipfeldmann opened this issue Jul 5, 2018 · 10 comments
Open

keyboard not working in games #62

philipfeldmann opened this issue Jul 5, 2018 · 10 comments

Comments

@philipfeldmann
Copy link

philipfeldmann commented Jul 5, 2018

Hey there.
Dispatching keys is not working in games for me.
keyboard.click(robot.KEY_Q); for example is not doing anything when using it in a game window, it works when trying to dispatch it to a text-field though (even works with the ingame chat of the game).

Any suggestion or a fix?

Suprisingly, I've done something similar before with Java's Robot class and it worked just fine.

@dkrutsko
Copy link
Member

dkrutsko commented Jul 5, 2018

What game is this? Does it work with the Java Robot class in this game?

@philipfeldmann
Copy link
Author

philipfeldmann commented Jul 5, 2018

League of Legends, running in borderless mode. Yes it does work with Java Robot, which is really surprising to me. Also surprising that, when opening chat, the key will get dispatched to the ingame-chat correctly. It's just not working for invoking ingame commands.

(Also clicking with the mouse works perfectly fine)

@dkrutsko
Copy link
Member

dkrutsko commented Jul 5, 2018

Interesting, the keypress logic is the same as Java, so you can almost rule out in-game protections. would something like keyboard.click ('q') work. Perhaps you need shift? In which case it'll be keyboard.click ('+q').

@philipfeldmann
Copy link
Author

philipfeldmann commented Jul 5, 2018

I pretty much copied from the documentation but just in case, I tried the following:
(I imported as Robot so it's capitalized)

import Robot from 'robot-js';
// mouse stuff works even in game
    const mouse = Robot.Mouse();
    const pos = res[0];

    Robot.Mouse.setPos(pos.x, pos.y);
// this works in an editor for example but does nothing in the game
    const keyboard = Robot.Keyboard();
    keyboard.click('q')
    keyboard.click(Robot.KEY_Q)
    keyboard.press(Robot.KEY_Q)
    keyboard.release(Robot.KEY_Q)

Like I said it's working for the chat but unfortunately that's not really helpful.

@dkrutsko
Copy link
Member

dkrutsko commented Jul 5, 2018

I remember looking at a game a while back where if the window was not in focus, it would ignore all input, this doesn't apply in this case. It also very foolishly ignored injected input which prevented certain hardware from working, so they had to patch it.

I wonder if anybody else has ran into this problem, perhaps it has some special logic to ignore node.exe specifically, I wouldn't put it past them. To properly test it, I'd build an application using the C++ version of robot and see if it works. I never played League but maybe it's something I'll be able to install.

@philipfeldmann
Copy link
Author

Well for LoL, when the game is not in focus, even when in the front, it will not accept any keyboard input, not even from the keyboard. But I've made sure it's focused and regular keyboard input, same as the java robot input works. Unfortunately I don't really have a good idea about c++ but if I find the time I'll see if I can compile a small demo to check if it works.

Anyway, thanks for your effort.

@dkrutsko
Copy link
Member

dkrutsko commented Jul 6, 2018

Could you please also tell me what OS you're using?

@philipfeldmann
Copy link
Author

Sure. Windows 10 Professional and Node 10.6.
Could it probably have something to do with LoL's client (not the game though) being an electron app? Some collision or something.

@Laureckis
Copy link

Any news on this?

I'm working on a game controller, and planned to use this for programmable macros, but some games ignore the keyboard commands (as above, it works in chat input field).

Doesn't work on Guild Wars 2, but does work fine in Rimworld.

Using something like Joy2Key (which seems C++ based, but doesn't offer a library) works ok in games.

Windows 10, Node 10.

@p120ph37
Copy link

p120ph37 commented Oct 9, 2019

I had some issues with keypresses too. See my PR here: Robot/robot#116
You can also use my fork, which includes the patch by setting your dependency to "robot-js": "github:p120ph37/robot-js#prebuilt"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants