2
votes

I want to change the use of Ctrl to Spacebar for three commands in a game but not for everything cause then I can't use space to communicate. The normal commands are Ctrl+q, Ctrl+w, Ctrl+e, Ctrl+r and Control+RButton (right mouse). Right now I'm usng Space::Ctrl, however I have tried different solutions with no result.

[EDIT/]
@MCL Ok. I looked at the forum thread you posted and tried the code below which sorta worked. It sent the keys how I wanted, but each shortcut triggered all shortcuts that followed it. For example space+e triggers space+e, space+r and space.

Also, Spacebar still didn't work. I added the Space::Space later and I can get a text space only by using the Space+(q, w, e or r) shortcuts.

SendMode Input
SetKeyDelay ,0,30

#IfWinActive ahk_class RiotWindowClass

Space & q::
            Send {Ctrl down}
            Sleep 30
            Send {q down}
            Sleep 30
            Send {q up}
            Sleep 30
            Send {Ctrl up}

Space & w::
            Send {Ctrl down}
            Sleep 30
            Send {w down}
            Sleep 30
            Send {w up}
            Sleep 30
            Send {Ctrl up}

Space & e::
            Send {Ctrl down}
            Sleep 30
            Send {e down}
            Sleep 30
            Send {e up}
            Sleep 30
            Send {Ctrl up}

Space & r::
            Send {Ctrl down}
            Sleep 30
            Send {r down}
            Sleep 30
            Send {r up}
            Sleep 30
            Send {Ctrl up}

Space & RButton::
            Send {Ctrl down}
            Sleep 30
            Send {RButton down}
            Sleep 30
            Send {RButton up}
            Sleep 30
            Send {Ctrl up}

Space::Space

#IfWinActive

[/EDIT]

2
Are you positive, that AHK sends your keys? Otherwise, the game could be your problem, blocking simulated keystrokes (maybe selectively). Also, to keep the original functionality of space, just add SPACE::Send, {SPACE} to your code. Find out the problem methodically: 1. Does AHK register your keypress? 2. Does AHK send your shortcut in general? (Try it outside your game first!) 3. Does your window receive AHK simulated keystrokes?MCL
Thanks MCL for your time. || I tested the following just now: Space & q::Send Text - It sent it to Notepad++ || Space & q::Send !q - I set Ctrl+q as shortcut for Launchy and it opened it successfully. So it seems the Send command is not working in the game. However, Space::Ctrl works. I Hit Space+q with that remap and the game detects it as Ctrl+q.Aristides Colon-Castillo
Just a hunch, but try to play around with the following directives: #InstallKeybdHook and #UseHook in different combinations (just put them at the top of your script). Also, find out if AHK registers your keypress (best by writing something into a file).MCL
Btw: Have a look at this thread in the AHK forum. Seems, that modifying SetKeyDelay can get it done.MCL
@MCL Ok It tried the suggestions on the thread you posted and edited my question according to the results I got.Aristides Colon-Castillo

2 Answers

0
votes

Found it. I needed to add the returns.

#NoEnv
SendMode Input
#InstallKeybdHook
#UseHook

#IfWinActive ahk_class RiotWindowClass

Space & q::
            Send {Ctrl down}
            Sleep 30
            Send {q down}
            Sleep 30
            Send {q up}
            Sleep 30
            Send {Ctrl up}
            return

Space & w::
            Send {Ctrl down}
            Sleep 30
            Send {w down}
            Sleep 30
            Send {w up}
            Sleep 30
            Send {Ctrl up}
            return

Space & e::
            Send {Ctrl down}
            Sleep 30
            Send {e down}
            Sleep 30
            Send {e up}
            Sleep 30
            Send {Ctrl up}
            return

Space & r::
            Send {Ctrl down}
            Sleep 30
            Send {r down}
            Sleep 30
            Send {r up}
            Sleep 30
            Send {Ctrl up}
            return

Space & RButton::
            Send {Ctrl down}
            Sleep 30
            Send {RButton down}
            Sleep 30
            Send {RButton up}
            Sleep 30
            Send {Ctrl up}
            return

Space::
            Send {Space}
            return

#IfWinActive
0
votes

Regarding : "Space will only work as text and won't work as the shortcut to center camera on your character."

Try using SendMode Play instead of SendMode Input.

SendPlay's biggest advantage is its ability to "play back"
keystrokes and mouse clicks in a broader variety 
of games than the other modes. 

-- From the documentation for SendPlay.

For further reading about Send mode settings, tradeoffs & abilities, check out the documentation for SendMode .


Regarding : SetKeyDelay

SendMode Input will not be effected by SetKeyDelay:

Note: SendInput ignores SetKeyDelay 
because the operating system does not support 
a delay in this mode.

-- From the documentation for SendInput


Additional information :

One thing to be aware of when using Custom Combinations (docs)
(i.e. using non-modifier keys for hotkey combinations):

when you defined the first Space & otherkey::, the Space key becomes a "prefix key", which means it loses its native function. This necessitated the final hotkey you defined in your example :

Space:: 
     Send {Space}
return

A note of caution : this hotkey (which restores functionality to the prefix key) fires when Space is released. And it will not fire if any other key is pressed between Space down and Space up.


Your script works as expected otherwise in Notepad++ (replacing the Send lines with MsgBox for debugging).

So this is likely an issue with the game picking up AHK's sent space key.

Try debugging by making a simple script which does nothing other than sending Space to the game using different SendModes.