octalmage / robotjs

Node.js Desktop Automation.
http://robotjs.io
MIT License
12.35k stars 954 forks source link

Not working when a game window is focused #210

Open Vahelnir opened 8 years ago

Vahelnir commented 8 years ago

Hello everyone, First, i'm sorry if there is any mistake. Second, i'm also sorry if this was already asked but i didn't find it. Actually, i don't really know if the issue is due to RobotJS, NodeJS or Windows but when i try to do for example 2 mouseClick() on a game window when it is focused, only the first click works.

EDIT: I'm a working with a vanilla nodejs script in cmd Thank you for the help.

octalmage commented 8 years ago

Hi @Vavaballz, which version of RobotJS are you using? And which game?

Vahelnir commented 8 years ago

The last one, 0.4.4. I tried with CS:GO and with Warframe.

demipixel commented 8 years ago

TF2 here, same issue.

jdtzmn commented 8 years ago

Minecraft here, same issue

OS: Mac 10.11.6 Game: Minecraft

I also tried using the "move-mouse-drag" branch, but to no avail... 😭 (I downloaded the 0.4.4 branch, then manually edited the files so that they were in sync with the 0.3.7 "move-mouse-drag" branch)

octalmage commented 8 years ago

This seems to be an issue for both Mac and Windows? Does the issue happen if the game isn't fullscreen?

Vahelnir commented 8 years ago

Yes, my first try with with warframe, warframe was fullscreen windowed

CarpeNecopinum commented 8 years ago

OS: Windows 7 Game: Lego StarWars Complete Saga RobotJS version 4.40

Similar problem, keys get stuck once pressed, until I tab out of the game and back in. Except for the arrow keys which are released properly.

PS: Using DxWnd to force the game into windowed mode does not help.

CarpeNecopinum commented 8 years ago

This might in fact be fixed when #218 is fixed/executed. I edited my application to use autoit (https://github.com/xhawk18/node-autoit) instead of robotjs and that makes it work flawlessly with Lego StarWars. That means it only works on windows for now.

Those who are testing under Windows should try using the autoit module and report their results....

ahiddenwaffle commented 8 years ago

Nope, running windows, even tried autoit, trying to run VisualBoyAdvance (Gameboy Emulator) Only first input registers.

octalmage commented 8 years ago

I will try to look into it this weekend, Windows isn't my first OS, so it's more difficult to look into this kind of stuff.

octalmage commented 8 years ago

@jdtzmn I spent some time testing this, and I wasn't able to replicate:

I haven't tested on Windows yet. Was this similar to what you were trying? Here's the code I used:

var robot = require('robotjs');

setInterval(function() {
    robot.mouseClick();
    console.log('Clicked.');
}, 2000);
jdtzmn commented 8 years ago

Oh... thought this was about moving the mouse, not clicking... 😜

giacomocerquone commented 7 years ago

So here another problem that I've encountered too on windows 10, it could be slightly different but still can be originated from the same malfunctioning code. It's not only games, to test this I pressed f11 on chrome and I can't write anymore, but it seems that only letters keys don't work anymore, in fact if I press f11 again chrome get out from fullscreen mode and everything return to work normally.

UPDATE: I noticed one thing (this may be a problem that occurs only to me). I am a js developer and when I work on the console (and start a js script with node to say) it happens sometime that I have to wakeup powershell (same thing happen with the cmd) with some sort of input (it can be the right click of the mouse or the return key) and then it starts the execution that had to start before... it's like it goes in stand-by. I said this because this is exactly what happens when I play on full-screen, I come back on powershell and I've to wake it up with some input.

DJLennard commented 7 years ago

Is there a solution yet?

vsdmoraes commented 6 years ago

Any update on this issue?

zapk commented 6 years ago

Happening to me, mouse doesn't work at all in CS:GO.

GenericPirate commented 6 years ago

Yeah here too, whats the cause for it? Want to use it to run automated tests on game builds ...

zapk commented 6 years ago

Does anyone know any alternatives that work?

gloatoriginal commented 5 years ago

Same, trying on GlobalMu atm and doesn't register left or right clicking

upkanet commented 5 years ago

Same problem with Elite:Dangerous. First keyTap works and then nothing else work. I tried with vJoy to send joystick button press instead of keyTap with RobotJS : same issue

I want to use a virtual keyboard on a tablet, but I guess it is some kind of anti-cheat mechanism (like gameguard or xigncode) that prevents inputs from suspicious programs.

Does it appear only on Online Games ? I would be a hint...

nitti87 commented 5 years ago

I've the same issue. It won't click again after the first click. Here is my code: const robot =require('robotjs'); let timeout; window.addEventListener('mousemove',()=>{ clearInterval(timeout); timeout = setTimeout(()=>{ robot.mouseClick('left',false); console.log('clicked ') }, 1000); })

oktapodia commented 4 years ago

@upkanet @nitti87 can you please provide a reproducible code? I can't reproduce it

dogue commented 4 years ago

I'm having a similar issue with Elite: Dangerous. keyTap() works as expected with the Home key (I can spam it and the game responds as if I were doing so on the actual keyboard), but other keys respond only once until I click out of the game and back in.

CrimsonVex commented 4 years ago

any update on this?

zedd3v commented 4 years ago

Having a similar issue. When working with windowed fullscreen games which keep the mouse in middle, the mouse position is very weird

gigadeplex commented 4 years ago

Hey guys, I was having this problem too on Win10. After spending some time on it, it seems to be a permissions error. So just run your program as admin. If you're running your program from a terminal, make sure you're running that terminal as admin.

anthonymesa commented 3 years ago

I just encountered this same issue and this seems to be the only thread on the internet that I can find where the issue has been brought up. Is there a fix for this yet, or do we know what the actual issue is? (I have tried running as administrator with no luck)

ArmandoPerdomo commented 3 years ago

Hey guys, I was having this problem too on Win10. After spending some time on it, it seems to be a permissions error. So just run your program as admin. If you're running your program from a terminal, make sure you're running that terminal as admin.

This works for me. thank you

iloveyou1122 commented 2 years ago

I launch my IDE (VSCode) with administrator just solved the problem.