Please help with LOOP Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Demetrius
Posts: 6
Joined: 06 Jun 2018, 05:42

Please help with LOOP

15 Jun 2018, 04:35

My script should be exactly with "GetKeyState" and with the "If" construction. But an error with "Loop" is shown. How do I properly build this script?

Code: Select all

Loop 
{
GetKeyState, state, NumpadEnd  
GetKeyState, state2, 1
if  ( state = D   
   and  state2 = D ) ; It is checked if the keys are pressed 
   loop ; If the keys are pressed, then it is checked whether they are released
   {  
      if ( state = U )  
         and ( state2 = U ) ; Keys released
      { MsgBox, "Keys are pressed and released NumPadEnd и 1"
       break } 
      }  
 
GetKeyState, state, NumpadEnd  
GetKeyState, state2, 2
if ( state = D )  
   and ( state2 = D ) ; It is checked if the keys are pressed 
   loop ; If the keys are pressed, then it is checked whether they are released 
   {  
      if ( state = U ) 
         and ( state2 = U ) ; ; Keys released
      { MsgBox, "Keys are pressed and released NumPadEnd и 2" 
       break 
        } 
      }  
}
Last edited by Demetrius on 15 Jun 2018, 06:00, edited 1 time in total.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Please help with LOOP

15 Jun 2018, 05:39

your script currently checks state for equality with an empty string. (variable D)
change that to check against the string "D".
I hope that helps. untested.

PS: same applies to U and "U"
same applies to state2
mshafer1
Posts: 54
Joined: 16 Jul 2017, 14:49
Contact:

Re: Please help with LOOP  Topic is solved

15 Jun 2018, 07:34

It think the issue is just a syntactical/formatting difficulty

Code: Select all

Loop 
{
    GetKeyState, state, NumpadEnd  
    GetKeyState, state2, 1
    if( state = D and  state2 = D ) ; It is checked if the keys are pressed 
        Loop ; If the keys are pressed, then it is checked whether they are released
        {
          if ( state = U and state2 = U ) ; Keys released
          { 
            MsgBox, "Keys are pressed and released NumPadEnd и 1"
            break 
          }
        }
    GetKeyState, state, NumpadEnd  
    GetKeyState, state2, 2
    if ( state = D and state2 = D ) ; It is checked if the keys are pressed 
        Loop ; If the keys are pressed, then it is checked whether they are released 
        {  
            if ( state = U and state2 = U ) ; ; Keys released
            {
                MsgBox, "Keys are pressed and released NumPadEnd и 2" 
                break 
            } 
        }  
}
Note: did not test functionality, but it does run
Demetrius
Posts: 6
Joined: 06 Jun 2018, 05:42

Re: Please help with LOOP

15 Jun 2018, 08:00

mshafer1 wrote:It think the issue is just a syntactical/formatting difficulty

Code: Select all

Loop 
{
    GetKeyState, state, NumpadEnd  
    GetKeyState, state2, 1
    if( state = D and  state2 = D ) ; It is checked if the keys are pressed 
        Loop ; If the keys are pressed, then it is checked whether they are released
        {
          if ( state = U and state2 = U ) ; Keys released
          { 
            MsgBox, "Keys are pressed and released NumPadEnd и 1"
            break 
          }
        }
    GetKeyState, state, NumpadEnd  
    GetKeyState, state2, 2
    if ( state = D and state2 = D ) ; It is checked if the keys are pressed 
        Loop ; If the keys are pressed, then it is checked whether they are released 
        {  
            if ( state = U and state2 = U ) ; ; Keys released
            {
                MsgBox, "Keys are pressed and released NumPadEnd и 2" 
                break 
            } 
        }  
}
Note: did not test functionality, but it does run


it does run, but it doesn't functions
Demetrius
Posts: 6
Joined: 06 Jun 2018, 05:42

Re: Please help with LOOP

15 Jun 2018, 08:02

Code: Select all

Loop 
{
    if( GetKeystate("NumpadEnd") = 1 and  GetKeystate("1") = 1 ) ; It is checked if the keys are pressed 
        Loop ; If the keys are pressed, then it is checked whether they are released
        { 
          if( GetKeystate("NumpadEnd") = 0 and  GetKeystate("1") = 0 ) ; Keys released
          { 
            MsgBox, "Keys are pressed and released NumPadEnd и 1"
            break 
          }
        }
if( GetKeystate("NumpadEnd") = 1 and  GetKeystate("2") = 1 ) ; It is checked if the keys are pressed 
        Loop ; If the keys are pressed, then it is checked whether they are released 
        {   
            if( GetKeystate("NumpadEnd") = 0 and  GetKeystate("2") = 0 ) ; ; Keys released
            {
                MsgBox, "Keys are pressed and released NumPadEnd и 2" 
                break 
            } 
        }  
}


I fixed it, it works well now. Thank you very much to everyone who answered! :dance: :bravo:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, jaka1, LuckyJoe, Rohwedder and 331 guests