Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Very simple boolean if statement loop. Confused about AH syntax.



  • Please log in to reply
6 replies to this topic
FackJack
  • Members
  • 4 posts
  • Last active: Oct 23 2015 01:10 PM
  • Joined: 22 Oct 2015

Hello

 

I have a very simple loop but I can't get it to work. I tried to look at the forums but there are so many different flavors of pseudo code here that I simply do not know what to write. Some use parenthesis, some do not. Some assign variables with = some with :=

 

Could someone take a look at my script and help me out?

 

The reason I use key up is that my mouse software doesn't send a key held command.

x := false


<+F1:: x := true
<+F1 Up:: x := false


if (x)
loop
{
Send ^{Numpad4}
if (!x)
break
}


Return


dmg
  • Members
  • 2395 posts
  • Last active: Nov 04 2015 06:46 AM
  • Joined: 19 Nov 2010

Greetings FackJack. Welcome to the wonderful, if slightly confusing world of AutoHotkey.

 

From your code it looks like you want a loop that runs while you hold the hotkey? You say you use the key up part because of your mouse software? What does your mouse have to do with this? There is nothing in your code regarding the mouse. Have you tried another method other than the down/up hotkeys?

 

Details are our friends. B)


"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

-----------------------------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact

Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

Here's something of interest for you as you learn:

 

x := false


<+F1:: x := true
<+F1 Up:: x := false

 

That is the only code that is capable of running in your script. Your first line is inside the auto-execute section. As soon as your first hotkey is introduced, the auto-execute section ends. Single line hotkeys have an implicit return to them, and any code beneath them is not executed when the hotkey is. Right now all your script is capable of doing is setting x to a true or false value. There is no way in which the other code you had is being run. You might have wanted to use a multiple-line hotkey, which requires nothing (except a comment) to come to the right of the double colon.

 

It sounds to me like you want to make the first hotkey, the <+F1:: a multiple-line hotkey and to run the loop below. You can indeed get the loop to break by using your <+F1 Up:: to set the value of x to false.



FackJack
  • Members
  • 4 posts
  • Last active: Oct 23 2015 01:10 PM
  • Joined: 22 Oct 2015

Greetings FackJack. Welcome to the wonderful, if slightly confusing world of AutoHotkey.

 

From your code it looks like you want a loop that runs while you hold the hotkey? You say you use the key up part because of your mouse software? What does your mouse have to do with this? There is nothing in your code regarding the mouse. Have you tried another method other than the down/up hotkeys?

 

Details are our friends. B)

Thank you .

 

I'm using Logitech SetPoint to assign a key to Shift + F1. The problem is that SetPoint doesn't send a key held down command to the computer. That is why I'm using AutoHotkey.

 

I use Ctrl + Numapad4 to pan the view in Blender.



FackJack
  • Members
  • 4 posts
  • Last active: Oct 23 2015 01:10 PM
  • Joined: 22 Oct 2015

You might have wanted to use a multiple-line hotkey, which requires nothing (except a comment) to come to the right of the double colon.

I'm sorry, but I don't understand. Why would I want to make a comment? Aren't comments discarded in machine language?

 

I can't infer what you mean unfortunately. I would love for someone to give a non-pseudo code example.



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012
✓  Best Answer

Yes, comments are ignored by the computer and are for the aid of human readers.

 

<+F1::
x:=true
Loop
{
Send ^{Numpad4}
If (!x)
Break
}
return
 
<+F1 up::x:=false

 

That is real code, but I haven't tested it. Try it out both with the keyboard and with your setpoint mouse if it doesn't seem to work, so we know if it's a problem with the mouse or a problem with the code.



FackJack
  • Members
  • 4 posts
  • Last active: Oct 23 2015 01:10 PM
  • Joined: 22 Oct 2015

That worked almost flawlessly. I just added sleep, 10 to make it work without bugging out Windows.

 

I get the syntax better now. I have to invoke the loop in some way.

 

Thank you very much Exaskryz.