Why is 'Send {Enter}' not working in a game?

3.2k Views Asked by At

I'm trying to make an AHK script to Send the Enter key to Red Dead Redemption 2. The {Enter] key is not sent inside the game at all.

It looks like I'm not the only one, but I did not achieve anything poking around https://www.reddit.com/r/AutoHotkey/comments/6goby1/how_to_send_enter_key/ https://www.autohotkey.com/boards/viewtopic.php?t=25880 https://www.autohotkey.com/board/topic/109564-pressing-enter-physically-is-not-the-same-as-send-enter-why/

So far here is what I have tried (I omited the Sleep, 300 between each command) :

NumpadIns::
Send {NumLock}

; -------------------- Send
Send {Enter}
; -------------------- SendEvent
SendEvent {Enter}
; -------------------- SendInput
SendInput {Enter}
; -------------------- SendPlay
SendPlay {Enter}
; -------------------- SendInput `n
Sendinput {`n}
Sendinput {`r}
Sendinput {`r`n}
Sendinput {\n}
Sendinput {\l\n}
; -------------------- ControlSend
ControlSend ,{Enter}, A
ControlSend, Edit1, {Enter}, RDR2.exe
ControlSend, Edit1, {Enter}, Red Dead Redemption 2
; ----------------- Random stuff

Run, powershell.exe -noexit -file "D:\enter.ps1"

sendMode, Input

#InputLevel 1
SendEvent, {enter}

sendlevel, 1
sendEvent, {enter}

#InstallKeybdHook
#UseHook
Send {$Enter}

ExitApp
return

The Powershell script output (which confirms the last 3 commands work) :

True
PS C:\Users\lucas\Desktop>
PS C:\Users\lucas\Desktop>

The Powershell script itself :

$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Red Dead Redemption 2')
Sleep 1
$wshell.SendKeys('~')

They all work everywhere, except in the game. Obviously, I also tried running it as admin, it works on any other app (e.g. Notepad++), etc. AutoIt makes the same result : everything works but directional Arrows and {Enter}

I also made a post on the modding forum : https://forums.nexusmods.com/index.php?/topic/8762513-rampage-trainer/page-346#entry123370128

Aswell as a video showing it so you get a better understanding. I'm stuck at positioning my NPCs https://www.youtube.com/watch?v=Sp_Hs-ErCOE

Any thoughts or alternative solutions ?

1

There are 1 best solutions below

0
devMark On

I'm afraid that if it works in your notepad but not in the game, the game may block it. But what helped me personally (in another game) is to switch to AutoHotkey v2. And btw, the SendInput event is most useful for sending keys to the game. I would just like to point out the syntax change that everything must now be in quotes now. E.g.

SendInput "{Enter}" 

or better shape for me is

SendInput("{Numpad0}").

If you want to send SendInput with variable, you should do it like this:

    KeyStroke(key) {
        key := someArrayOfGameKeys[key]
        SendInput '{' key '}'
    }