Spam Keys without using $ (CapsLock)? Topic is solved

Ask gaming related questions (AHK v1.1 and older)
d4v1dAHK
Posts: 16
Joined: 08 Feb 2023, 02:15

Spam Keys without using $ (CapsLock)?

Post by d4v1dAHK » 08 Feb 2023, 15:15

I need my keys to spam only while the key is pressed so found this script on here:

Code: Select all

$1::
while (getkeystate("1", "P")) {
send 1
sleep 50
}
return
Is there a script/way to spam a key without using "$" in the script?

This script spams the CapsLock input even before the input I intended, and in this game I want to use the 'CapsLock' key for an input as well. If it needs to be a hotkey, in order I'd prefer it to work with 'Alt', then 'Tab', then 'Ctrl'.

But, is there any way to have the key alone spam itself if that makes sense?

User avatar
boiler
Posts: 17080
Joined: 21 Dec 2014, 02:44

Re: Spam Keys without using $ (CapsLock)?

Post by boiler » 08 Feb 2023, 17:13

d4v1dAHK wrote: But, is there any way to have the key alone spam itself if that makes sense?
What do you mean by the "key alone"? Are you thinking that the $ means that you are supposed to press $ while pressing the other key? The $ is there to prevent the hotkey from triggering itself when it sends 1. You still press only 1 to trigger the hotkey manually. See Hotkey Modifier Symbols for further explanation.

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Spam Keys without using $ (CapsLock)?

Post by DuckingQuack » 08 Feb 2023, 18:14

@d4v1dAHK I tested the script provided and it appears to only spam the number one. How did you determine the CapsLock is being spammed? The Key History log?
On a side note, the $ is absolutely necessary for the script to function correctly.
Best of Luck,
The Duck

d4v1dAHK
Posts: 16
Joined: 08 Feb 2023, 02:15

Re: Spam Keys without using $ (CapsLock)?

Post by d4v1dAHK » 08 Feb 2023, 18:54

@boiler To activate the output I've only been pressing "1". But in the game, before it registers "1" it registers and uses the ability assigned to CapsLock. Which makes me not able to use the CapsLock as an input for a different ability.
@DuckingQuack I had a feeling that it wouldn't 'work alone' seeing that "hotkey" is in the name of the program. Yes, in the browser for example it does only spam "1". But in game it inputs CapsLock before "1". And it looks like using ^(Ctrl) and !(Alt) to replace "$" doesn't work.

It's all good, I'm grateful the program still helped me get 2 inputs to spam automatically as intended. I switched the CapsLock input ability to slightly less convenient TAB input for now at least. Thanks for the help.

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Spam Keys without using $ (CapsLock)?

Post by DuckingQuack » 08 Feb 2023, 19:20

@d4v1dAHK I believe you still have a misunderstanding as to what the $ does. Please refer to the page boiler asked you to read up on, at least scroll to the $ section and read that single paragraph. Hopefully, the take away is that nothing in this script is activating the CapsLock and therefore troubleshooting needs to take place to locate what is causing this problem.
boiler wrote:
08 Feb 2023, 17:13
See Hotkey Modifier Symbols for further explanation.
Edit: For clarity's sake... "CapsLock" does not have a hotkey modifier symbol, therefore, "$" will never mean "CapsLock."
Best of Luck,
The Duck

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Spam Keys without using $ (CapsLock)?

Post by DuckingQuack » 08 Feb 2023, 20:25

@d4v1dAHK I am interested in assisting you, so I think maybe breaking down exactly what's going on in the script might be beneficial.

Code: Select all

$1::    ; Here we are creating a hotkey that is ONLY activated by the "1" on the keyboard and any other sources of a "1" will be ignored.
while (getkeystate("1", "P")) {     ; Here we are saying that while the logic-state of the "1" key on the keyboard is Physically pressed, we will do the following things:
send 1     ; First thing we do is send "1" as an input to the game.
sleep 50     ; Next we will wait 0.050 seconds.
}
return     ; This is the end of the script and it cycles back to the beginning since a script with a hotkey is considered to be persistent.
Hopefully this was helpful.
Please note that nowhere was CapsLock mentioned, which means we must figure out what crazy interaction is causing this phenomenon.
Best of Luck,
The Duck

d4v1dAHK
Posts: 16
Joined: 08 Feb 2023, 02:15

Post by d4v1dAHK » 08 Feb 2023, 23:07

@DuckingQuack I see now. When I had tried using "^", "!" and "+" before trying "$", there was always an issue related to the modifier those syntaxes represented. So when I tried using "$" and it registered CapsLock before the intended input, I assumed the "$" syntax was related to CapsLock.

I definitely do not understand all this stuff really, but the fact still remains that the game is registering the CapsLock before the intended function. After typing this previous sentence I tested and confirmed that my CapsLock keys' light indicator also blinks (from getting a spammed input) in the browser too when clicking "1" with the script running.

Note that I tried clicking the input (1) very fast so that it only inputs "1", one time (instead of allowing it to spam), and it does *not* actually activate or deactivate CapsLock. (So it's just clicking CapsLock without actually activating it.?)
Note that the CapsLock is not input when I tried using the other hotkey modifier syntax.

If you have any suggestions to try and troubleshoot, I'll try it out.

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Spam Keys without using $ (CapsLock)?

Post by DuckingQuack » 09 Feb 2023, 06:11

Okay, well, we’ll check the basics first.
  • (1) Are you using a normal or specialized keyboard? A gaming keyboard has the potential to do weird things but it alone wouldn’t be the problem. Usually a macro that they have bound to them will cause problems.
    (2) Are you using multiple scripts at the same time? Again, not inherently a problem unless they have conflicting or overlapping code or hotkeys. If you post ALL of the code you’re using, I can more easily assist with inspecting it.
    (3) What game are you playing? It could be a bug related to the game, although this is unlikely, it’s still a possibility.
    (4) If you have multiple scripts running together, try to run this script only and see if you are still experiencing this issue.
Best of Luck,
The Duck

d4v1dAHK
Posts: 16
Joined: 08 Feb 2023, 02:15

Re: Spam Keys without using $ (CapsLock)?

Post by d4v1dAHK » 10 Feb 2023, 22:42

@DuckingQuack 1. My keyboard is Logitech Master Keys.

2.

Code: Select all

$Tab::
 suspend permit
;bypasses suspend on commands

while (getkeystate("Tab","p")) {
;as long as tab is held down...

send, {Tab}
sleep 100
}
return


$2::
while (getkeystate("2", "P")) {
send 2
sleep 100
}
return


$3::
while (getkeystate("3", "P")) {
send 3
sleep 100
}
return

4. I'm going to assume 'one script' is 1 section?/function? If it is, this was happening from when I only had one script running.

I realized something new though, it only clicks CapsLock if my CapsLock is on. If my CapsLock is not on, it won't register the input.
Last edited by d4v1dAHK on 15 Oct 2023, 12:29, edited 1 time in total.

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Spam Keys without using $ (CapsLock)?

Post by DuckingQuack » 10 Feb 2023, 23:41

A script is the entire text file that you run that has an extension of either “.ahk” or “.exe” after being compiled. If you have to “run” more than one file, then you are running multiple scripts.

Thank you for the additional information, I’ll have some time to dig into this tomorrow.
Best of Luck,
The Duck

gregster
Posts: 9066
Joined: 30 Sep 2013, 06:48

Re: Spam Keys without using $ (CapsLock)?  Topic is solved

Post by gregster » 11 Feb 2023, 02:03

d4v1dAHK wrote:
10 Feb 2023, 22:42
I realized something new though, it only clicks CapsLock if my CapsLock is on. If my CapsLock is not on, it won't register the input.
Yes, Capslock is a special key with its own behaviour.

On my keyboard layout (it might differ for yours), you'll get a !, if you press the 1 key, while Capslock is ON.
that's why if I

Code: Select all

send 1
while Capslock is ON, AHK tries to counter that by first releasing Capslock, sending 1, and then restoring the Capslock state to ON.
So 1 actually gets sent, not !.

If you want to keep Capslock ON no matter what you send, then you have to use some different send mode.
You could try Text mode (AHK v1.1.27+):

Code: Select all

send {text}1
Now, AHK uses a different send mode to send 1 (not !), without affecting the Capslock state.
No idea, if your game will like that different send method.

If your game already accounts for Capslock ON, and then actually expects ! instead of 1, you could try blind mode:

Code: Select all

Send {blind}1
This won't release an activated Capslock, and it will then send ! instead of 1. Or whatever a shifted 1 results in on your keyboard layout.

After all, I guess you could try to define different hotkey variants for different Capslock states, with #If...

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Spam Keys without using $ (CapsLock)?

Post by DuckingQuack » 11 Feb 2023, 07:26

@gregster good job! I was getting ready to suggest blind also. Excellent explanation, too.
@d4v1dAHK I’m pretty confident @gregster solved this one for you, I’ll keep watching the thread in case you have any more questions.
Best of Luck,
The Duck

d4v1dAHK
Posts: 16
Joined: 08 Feb 2023, 02:15

Re: Spam Keys without using $ (CapsLock)?

Post by d4v1dAHK » 11 Feb 2023, 18:34

@gregster "{text}" didn't work. But thankfully "{blind}" fixed the issue, and I can use inputs w/o it registering the CapsLock input now.

There's one more thing that I'd like to get automated. Inputs from my mouse. Say I set my mouse side button to hit "1", with the script running it doesn't register the input at all (*from my mouse*).
DuckingQuack wrote:
08 Feb 2023, 20:25
@d4v1dAHK I am interested in assisting you, so I think maybe breaking down exactly what's going on in the script might be beneficial.

Code: Select all

$1::    ; Here we are creating a hotkey that is ONLY activated by the "1" on the keyboard and any other sources of a "1" will be ignored. ... 
I'm assuming this is related to the comment on the "$1::" line? Any suggestion to have automated inputs work from my mouse as well?
If it helps, the mouse I have is the Logitech Anywhere 2s and it uses Logi Options+ software to program the buttons.

If not, I have been using an app called "X-Mouse Button Control" to automate other inputs. But it has a slight delay in registering whatever input I want automated.

d4v1dAHK
Posts: 16
Joined: 08 Feb 2023, 02:15

Post by d4v1dAHK » 11 Feb 2023, 19:54

Also, is there a way to force an input (right now, Ctrl) to strictly only be able to be registered 1 time upon being pressed, even if it is pressed and held?

In game you have a passive state that you can't use abilities from, and an active state where you can use your abilities. I use my Ctrl button to activate AND deactivate being passive or active.
You can program the input in game, & if you hold whatever input you have it programmed too (in my case its Ctrl) to activate & deactivate it, it will constantly take you in and out of combat.

I searched around google and found "KeyWait". So I tried these four scripts separately.

Code: Select all

$Ctrl::
Send Ctrl
KeyWait, Ctrl
return

$^::
Send ^
KeyWait, ^
return

$^::
Send Ctrl
KeyWait, Ctrl
return

$Ctrl::
Send ^
KeyWait, ^
return
It may be that the game forces it to be spammed. idk. But I did try searching and experimenting w/ stuff before asking for more assistance.

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Spam Keys without using $ (CapsLock)?

Post by DuckingQuack » 11 Feb 2023, 20:06

On the topic of the mouse: if your button you wish to be the new hotkey is already listed in AHK, then swap the hotkey to be the mouse button (AHK natively supports LB, MB, RB, X1, X2, so if the button is recognized as one of those, then you’re all set).

On the topic of the Ctrl issue: AHK works exactly as you described… if you make a hotkey like a::a then no matter how long you hold down a, you only get one ‘a’… now the actual problem here is more likely to be with direct x grabbing the keyboard inputs and sending them to the game… a work around for that is to set your “combat mode” button to a different key that isn’t used such as F12 (idk, just a guess) and then set ctrl::{F12}… that’s just a rough idea to work with. Let me know if you need anything else
Best of Luck,
The Duck

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Spam Keys without using $ (CapsLock)?

Post by DuckingQuack » 11 Feb 2023, 20:12

I just reread your post and realized that, Yes! You are right about the comment I put on the hotkey line. The script is using the keyboard hook to know that the 1 is actually coming from the keyboard, so the mouse being remapped probably wouldn’t work (and your test proves it doesn’t)

Edit:
So, expanding on the mouse, (some one please correct me if I’m stating this wrong) you can leave your $1:: there and add another hotkey directly above it like
XButton1::
$1::

This makes two buttons that do the same thing
Best of Luck,
The Duck

d4v1dAHK
Posts: 16
Joined: 08 Feb 2023, 02:15

Post by d4v1dAHK » 11 Feb 2023, 21:23

Ok I tried all of that. It doesn't work but it's ok. The mouse and ctrl thing were extra don't even sweat it anymore. You guys helped me do the most important things relating to this. Thank you.

d4v1dAHK
Posts: 16
Joined: 08 Feb 2023, 02:15

Spam Keys without using $ (CapsLock)?

Post by d4v1dAHK » 13 Feb 2023, 18:46

This is what I use now

Code: Select all

^capslock::Suspend
; ctrl + capslock hotkey to un/suspend this script


$CapsLock::
while (getkeystate("CapsLock","P")) {
send, {blind}{CapsLock}
sleep 100
}
return


$Tab::
while (getkeystate("Tab","P")) {
send, {blind}{Tab}
sleep 100
}
return


$3::
while (getkeystate("3", "P")) {
send {blind}3
sleep 100
}
return 

Post Reply

Return to “Gaming Help (v1)”