Basic question

Ask gaming related questions
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] [Download] (Untitled.ahk)GeSHi © Codebox Plus

*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: 339
Joined: 08 Jul 2015, 00:12
Contact:

Re: Basic question

21 Jan 2018, 12:53

Code: [Select all] [Download] GeSHi © Codebox Plus

*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] [Download] GeSHi © Codebox Plus

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

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] [Download] GeSHi © Codebox Plus

*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:



Hope this helps

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

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 3 guests