Page 1 of 1

Basic question

Posted: 21 Jan 2018, 11:13
by JkrAbram
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. :(

Re: Basic question

Posted: 21 Jan 2018, 12:53
by Spawnova

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

Re: Basic question

Posted: 21 Jan 2018, 13:03
by A_AhkUser
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...