Basic question

Ask gaming related questions (AHK v1.1 and older)
JkrAbram
Posts: 3
Joined: 21 Jan 2018, 07:54

Basic question

21 Jan 2018, 11:13

Hey,
I've just started using AHK, so this question is basic. Nevertheless, I need help with debugging something I made.

Code: Select all

*y::
If(!GetKeyState("Shift"))
{
; do nothing
} else {
; send, g
}

return
Essentially, I am saying that when I press y, the program will check if I am holding shift. If I am holding shift, the program will stop. Otherwise, if I am not holding shift, then g will be typed. I have looked at a few tutorials, and I can't find my error. :(
User avatar
Spawnova
Posts: 557
Joined: 08 Jul 2015, 00:12
Contact:

Re: Basic question

21 Jan 2018, 12:53

Code: Select all

*y::
If(!GetKeyState("Shift")) ;if NOT holding shift
{
;if NOT holding shift do nothing
} else {
;ELSE if holding shift send g
}
return
The above is what the code translates to

Looks like you had it backwards, a simple fix is just remove the !
or you can swap the code inside the brackets.

Code: Select all

;condensed code
y::
if (!GetKeyState("shift")) ;if NOT holding shift
	send g
return
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Basic question

21 Jan 2018, 13:03

Hi JkrAbram,
I can't find my error
Your code does quite the opposite; that is, it does nothing precisely if you're not holding shift; remove the logical not in front of the GetKeyState call:

Code: Select all

*y::
If (GetKeyState("Shift"))
	return ; end the subroutine
; otherwise...
MsgBox, OK
return
I suggest you using a #If context-sensitive double-colon hotkey instead (though in this particular case, practically, it simply allows Y - that is y in upper case - to be typed): actually the first code will block a priori each variant of y contrary to this other one:

Code: Select all

#If !GetKeyState("Shift")
*y::
MsgBox, test
return
#If
Hope this helps

[EDIT]
@Spawnova looks like you outstriped me...
my scripts

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 40 guests