[ahk v1] about '::' hotkey with 'send key' Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
norot41087
Posts: 8
Joined: 11 May 2024, 00:19

[ahk v1] about '::' hotkey with 'send key'

Post by norot41087 » 11 May 2024, 02:08

Code: Select all

Process, Priority, , A
#NoEnv
#NoTrayIcon
#KeyHistory, 0
#HotKeyInterval 99000000
#MaxHotkeysPerInterval 99000000
#SingleInstance force
#MaxThreadsBuffer on
#Persistent
SendMode, Input
ListLines, Off
SetKeyDelay,-1, -1
SetControlDelay, -1
SetMouseDelay, -1
SetWinDelay,-1
SetBatchLines,-1

Suspended := False
F4::
Suspend
Suspended := !Suspended
If (Suspended)
    SoundPlay, %A_WorkingDir%\soff.wav
Else
    SoundPlay, %A_WorkingDir%\son.wav
Sleep, 600
Return

*RButton::q
Return
and the question part is:

Code: Select all

*RButton::q
    Send, 'key'
Return
send command will not working.

how do I write the command that make it run same as `a:b` and `send 'key'` will working
also if it can work nice in v2, pls write it too.
Thanks.
User avatar
boiler
Posts: 17209
Joined: 21 Dec 2014, 02:44

Re: [ahk v1] about '::' hotkey with 'send key'

Post by boiler » 11 May 2024, 03:20

It’s not clear what you want to happen. When you right-click, do you want it to send q followed by 'key'? So you really want to send q'key'? Or are you not aware that the single quotes are part of what gets sent the way you’ve written it? Do you want to send qkey? Or is q not even meant to be a part of it?
norot41087
Posts: 8
Joined: 11 May 2024, 00:19

Re: [ahk v1] about '::' hotkey with 'send key'

Post by norot41087 » 11 May 2024, 06:48

boiler wrote:
11 May 2024, 03:20
It’s not clear what you want to happen. When you right-click, do you want it to send q followed by 'key'? So you really want to send q'key'? Or are you not aware that the single quotes are part of what gets sent the way you’ve written it? Do you want to send qkey? Or is q not even meant to be a part of it?
[Mod edit: Added translation:]
I apologize for my bad English and untranslation.
What I mean is that the RButton is assigned to q, and also sends q, and also sends the content after send.
For example

Code: Select all

a::b
send, {c}
I think when I press a, ahk sends b and c.
對我的糟糕英文和解譯感到抱歉。
我的意思是,RButton被指派為q,也發送q,同時也發送send後面的內容,
例如

Code: Select all

a::b
send, {c}
我想當我按下a時,ahk會發送b和c
Last edited by gregster on 11 May 2024, 07:43, edited 1 time in total.
Reason: Added translation. Please use English in the main forums!
User avatar
boiler
Posts: 17209
Joined: 21 Dec 2014, 02:44

Re: [ahk v1] about '::' hotkey with 'send key'

Post by boiler » 11 May 2024, 07:48

Then like I said, you want to send qkey. There is no reason to make a distinction between the q and the key. It doesn’t work like that. So your hotkey would be this:

Code: Select all

#Requires AutoHotkey v1.1.33
*RButton::Send, qkey

And in v2:

Code: Select all

#Requires AutoHotkey 2.0
*RButton::Send 'qkey'

Please use a translator yourself and post in English in the main part of the forum. Thanks, gregster, for adding the translations.
norot41087
Posts: 8
Joined: 11 May 2024, 00:19

Re: [ahk v1] about '::' hotkey with 'send key'

Post by norot41087 » 11 May 2024, 12:51

boiler wrote:
11 May 2024, 07:48
Then like I said, you want to send qkey. There is no reason to make a distinction between the q and the key. It doesn’t work like that. So your hotkey would be this:

Code: Select all

#Requires AutoHotkey v1.1.33
*RButton::Send, qkey

And in v2:

Code: Select all

#Requires AutoHotkey 2.0
*RButton::Send 'qkey'

Please use a translator yourself and post in English in the main part of the forum. Thanks, gregster, for adding the translations.
- I comprehend the situation; however, I am unable to edit the post until it receives your approval.

- I understand the purpose of the code you wrote. Here is what I discovered in the forum (viewtopic.php?p=570302#p570302), and below is the code I enhanced:

Code: Select all

*RButton::
{
SendKey("q")   
SendKey("c")   
}
SendKey(Key){

	VK := GetKeyVK(Key),SC := GetKeySC(Key)

		DllCall("keybd_event", "UChar", VK, "UChar", SC, "UInt", 0, "UPtr", 0)
		Sleep 17
		DllCall("keybd_event", "UChar", VK, "UChar", SC, "UInt", 2, "UPtr", 0)
}
It's unlikely that this code corresponds to RButton:: "q" and RButton:: "c"; it seems to be more akin to the code indicated below.

Code: Select all

*RButton::
    {
    Send "q"
    Send "c"
}

The optimal outcome for this code's successful execution would be to configure the RButton as the q-key, while also enabling it to transmit a "c" upon being pressed.

Code: Select all

RButton::"q"
    Send "c"
User avatar
boiler
Posts: 17209
Joined: 21 Dec 2014, 02:44

Re: [ahk v1] about '::' hotkey with 'send key'

Post by boiler » 11 May 2024, 13:53

norot41087 wrote: The optimal outcome for this code's successful execution would be to configure the RButton as the q-key, while also enabling it to transmit a "c" upon being pressed.

Code: Select all

RButton::"q"
    Send "c"
That’s not how it works, so you might as well stop posting that and move on to why sending qc doesn’t accomplish what you want.
User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: [ahk v1] about '::' hotkey with 'send key'

Post by mikeyww » 11 May 2024, 21:22

Just another idea here.

Code: Select all

#Requires AutoHotkey v2.0
*RButton::   Send('{Blind}{q DownR}'), Send('c')
*RButton Up::Send('{Blind}{q up}')
norot41087
Posts: 8
Joined: 11 May 2024, 00:19

Re: [ahk v1] about '::' hotkey with 'send key'

Post by norot41087 » 11 May 2024, 22:59

mikeyww wrote:
11 May 2024, 21:22
Just another idea here.

Code: Select all

#Requires AutoHotkey v2.0
*RButton::   Send('{Blind}{q DownR}'), Send('c')
*RButton Up::Send('{Blind}{q up}')
It's a great idea, and I believe I've attempted it before, though I'm not sure why I didn't pursue it further. Perhaps it's because I'm not entirely comfortable with AutoHotkey; most of the AHK code I use has been sourced directly from the internet. I try to comprehend its functionality and then modify it to suit my needs. :mrgreen: ,This indicates that I have no understanding of the fundamentals of AHK.)

I attempted your suggestion, but unfortunately, one game still detects that I'm using AHK to issue keyboard commands. Substituting wheelup/down works, but it doesn't prioritize the commands as highly as the keyboard does. For instance, if I want to send a command as soon as I press the RButton, "c" is transmitted to the game faster than "wheelup/down." My guess is that it might be due to the game using the EAC driver level to intercept mouse or keyboard commands.

Imagine you want to maintain the RButton pressed for in-game aiming while sending 'j' (presumed to be an emote) and then hitting 'q' (presumed to be a skill). If the 'j' command is not executed concurrently with the RButton, it will cause the in-game aiming to disengage, even though the RButton has not been physically released.
在下面的程式碼中,產生的行為RBtutton == 'RBtutton' , "j" == "{wheeldown}", "q" == "{wheelup}"

- This code should function properly within the game and not interfere with the continuous pressing of the RButton command.

Code: Select all

*RButton::   Send "j{Blind}{q DownR}"
*RButton Up::Send "{Blind}{q up}"
I assume that in-game commands such as "RButton down", "j", and "q down" are recognized either simultaneously or with minimal delay.


- The code functions correctly within the game; however, the "RButton down" command gets interrupted in-game, leading the game to mistakenly register the RButton as being continuously pressed, despite it being physically held down.

Code: Select all

*RButton::  
{ 
Send "{wheeldown}"
Send "{wheelup}"
}
I believe that among the in-game commands "RButton down", "{wheeldown}", and "{wheelup}", the "RButton down" command is executed first. Subsequently, the "{wheeldown}" command recognizes it and interrupts the ongoing press of the "RButton".
User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: [ahk v1] about '::' hotkey with 'send key'  Topic is solved

Post by mikeyww » 12 May 2024, 05:30

What the script does:
Configure the RButton as the q-key, while also enabling it to transmit a "c" upon being pressed.
If you want to send Q down and up upon the RButton press instead of having RButton act as Q, then you do not need the key-up hotkey.

On the other hand, to keep what you have and add J, add it before C.

A couple of things will aid you as you troubleshoot.
  1. Test in Notepad, so that you can see what happens and see it outside your game.
  2. Check the KeyHistory to understand what is happening with the keys.
You can then adjust so that you are sending whatever you want to send. Add Sleep if you need a delay.

V2 scripts use SendInput by default. Many games instead need SendEvent.

The following script sends the RButton and holds it while sending the three letter keys. Adjust as you wish.

Code: Select all

#Requires AutoHotkey v2.0
SetKeyDelay 25, 25
~RButton::SendEvent 'jqc'
AutoHotkey64240512-0628-002_cr2.png
Key history
AutoHotkey64240512-0628-002_cr2.png (47.63 KiB) Viewed 825 times
norot41087
Posts: 8
Joined: 11 May 2024, 00:19

Re: [ahk v1] about '::' hotkey with 'send key'

Post by norot41087 » 12 May 2024, 06:24

mikeyww wrote:
12 May 2024, 05:30
What the script does:
Configure the RButton as the q-key, while also enabling it to transmit a "c" upon being pressed.
If you want to send Q down and up upon the RButton press instead of having RButton act as Q, then you do not need the key-up hotkey.

On the other hand, to keep what you have and add J, add it before C.

A couple of things will aid you as you troubleshoot.
  1. Test in Notepad, so that you can see what happens and see it outside your game.
  2. Check the KeyHistory to understand what is happening with the keys.
You can then adjust so that you are sending whatever you want to send. Add Sleep if you need a delay.

V2 scripts use SendInput by default. Many games instead need SendEvent.

The following script sends the RButton and holds it while sending the three letter keys. Adjust as you wish.

Code: Select all

#Requires AutoHotkey v2.0
SetKeyDelay 25, 25
~RButton::SendEvent 'jqc'

AutoHotkey64240512-0628-002_cr2.png
Thank you for your assistance! I've implemented the improved code, and it no longer triggers the EAC detection.
—— Add random sleep numbers! ——
I was surprised to find such a simple solution, and although I've never used random numbers in any of my games before, this is indeed the first time.
At one point, I suspected that AutoHotkey (AHK) was causing the detection since the game employs driver-level monitoring for the left and right mouse buttons. Even when AHK is used to shield the keystrokes, they are still activated within the game.

Here's the code, I've utilized it for numerous games without activating the EAC detection, and I hope there will be no further issues in the future!

Code: Select all

#Requires AutoHotkey 2.0

#NoTrayIcon
#SingleInstance ;Force
#MaxThreadsBuffer ;1
KeyHistory 0
ListLines 0
SetKeyDelay -1, -1
SetControlDelay -1
SetMouseDelay -1
SetWinDelay -1
ProcessSetPriority 'A'
A_HotKeyInterval := 0
Persistent ;true


#SuspendExempt ;1

F8::
{
Suspend
Suspended := A_IsSuspended
If (Suspended)
    SoundPlay A_WorkingDir '\soff.wav'
Else
    SoundPlay A_WorkingDir '\son.wav'
Sleep 600
Return
}


#SuspendExempt False

*RButton::SendKey('j')
    Rand1:= Random(1, 21) 
    Rand2:= Random(355, 379)
    SendKey(Key)
        {
        VK := GetKeyVK(Key),SC := GetKeySC(Key)
        DllCall("keybd_event", "UChar", VK, "UChar", SC, "UInt", 0, "UPtr", 0)
        Sleep Rand1
        DllCall("keybd_event", "UChar", VK, "UChar", SC, "UInt", 2, "UPtr", 0)
    KeyWait 'RButton'
    Sleep Rand2
    }
    
;*RButton::   Send 'j{Blind}{q DownR}'
;*RButton Up::Send '{Blind}{q up}'
";code" is the code that triggers the EAC detection(for this game I play).
User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: [ahk v1] about '::' hotkey with 'send key'

Post by mikeyww » 12 May 2024, 07:16

OK. In v2, aside from labeled subroutines used with Goto or loops, code outside your functions will execute only when the script is first run. You do not need a variable called "Suspended" since AHK has a built-in variable for this status.
norot41087
Posts: 8
Joined: 11 May 2024, 00:19

Re: [ahk v1] about '::' hotkey with 'send key'

Post by norot41087 » 12 May 2024, 08:01

mikeyww wrote:
12 May 2024, 07:16
OK. In v2, aside from labeled subroutines used with Goto or loops, code outside your functions will execute only when the script is first run. You do not need a variable called "Suspended" since AHK has a built-in variable for this status.
Thank you for the suggestion to optimize the code. I appreciate your assistance once more. :bravo:

I have some inquiries regarding the difference between v1 and v2,
- does v2 match v1 in operational efficiency for commonly used code?
- does using version 2 reduce the likelihood of detection by anti-cheat systems compared to version 1?
User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: [ahk v1] about '::' hotkey with 'send key'

Post by mikeyww » 12 May 2024, 08:16

I'm not the authoritative source, but I don't think you'll notice any decreases in performance, and you may notice a variety of improvements with v2. Changes are summarized here.

https://www.autohotkey.com/docs/v2/v2-changes.htm

I did note that some lines with comma-separated statements might be slower, but it would not be a reason to avoid v2, since you can separate statements while you get the many other benefits of v2. V1 is deprecated and no longer being developed or fixed.

I am not aware of differences in how games detect v1 vs. v2, but I have not tested. You can run your own experiments to answer these questions.
norot41087
Posts: 8
Joined: 11 May 2024, 00:19

Re: [ahk v1] about '::' hotkey with 'send key'

Post by norot41087 » 12 May 2024, 08:34

mikeyww wrote:
12 May 2024, 08:16
I'm not the authoritative source, but I don't think you'll notice any decreases in performance, and you may notice a variety of improvements with v2. Changes are summarized here.

https://www.autohotkey.com/docs/v2/v2-changes.htm

I did note that some lines with comma-separated statements might be slower, but it would not be a reason to avoid v2, since you can separate statements while you get the many other benefits of v2. V1 is deprecated and no longer being developed or fixed.

I am not aware of differences in how games detect v1 vs. v2, but I have not tested. You can run your own experiments to answer these questions.
In coding, I understood there's often a trade-off between being easy to learn (v1) and easy to maintain (v2).
However, the web seems to have fewer examples of v2 compared to v1. Whenever I encounter a problem, the assistance available tends to be slightly more geared towards v1.
So based on your earlier reply, I would still like to continue using the code in the current v1.
I use v2 unless I need to write my own new code to work for me, like now lol.
User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: [ahk v1] about '::' hotkey with 'send key'

Post by mikeyww » 12 May 2024, 09:15

That decision is yours, of course. The v2 forum can help with questions and problems that you may encounter. Since v2 is newer, there are fewer posts about it, and somewhat fewer script libraries, though the numbers are growing quickly. Quickly counting the most recent posts made by thread on 11 May 2024, we see 8 threads updated in the v1 forum, and 15 in the v2 forum.

What is easier to learn may vary by individual. V2 offers greater consistency both internally and externally. Many new learners ultimately become confused by v1's legacy syntax and how or when to use expressions.
norot41087
Posts: 8
Joined: 11 May 2024, 00:19

Re: [ahk v1] about '::' hotkey with 'send key'

Post by norot41087 » 13 May 2024, 08:38

mikeyww wrote:
12 May 2024, 09:15
That decision is yours, of course. The v2 forum can help with questions and problems that you may encounter. Since v2 is newer, there are fewer posts about it, and somewhat fewer script libraries, though the numbers are growing quickly. Quickly counting the most recent posts made by thread on 11 May 2024, we see 8 threads updated in the v1 forum, and 15 in the v2 forum.

What is easier to learn may vary by individual. V2 offers greater consistency both internally and externally. Many new learners ultimately become confused by v1's legacy syntax and how or when to use expressions.
For `keybd_event` (or `sendevent`) and `keybd_input` (or `sendinput`), who do you think would be a better choice to use in terms of your philosophy of ahk's excellent functioning, given that both work fine?
User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: [ahk v1] about '::' hotkey with 'send key'

Post by mikeyww » 13 May 2024, 09:04

If both work, then there is no better option. You can take your pick.
Post Reply

Return to “Ask for Help (v1)”