title: Basic app in AHK - main loop and flow control
body: <p>I want to write a small app with AHK, but I'm facing
  difficulties in understanding the very basics of 
  the flow control and the syntax.
  So basically the question can be understood as - how do I write a 
  simple program in AHK?</p>
  
  <p>Here is a very simple program which must toggle 
  the flag "pan_on" with the right mouse button.
  Then do something depending on this value.</p>
  
  <pre><code>pan_on := false
  
  Esc:: ExitApp
  
  Rbutton:: 
      tooltip,  "button pressed"
      pan_on := true
  return
  
  Rbutton up:: 
      tooltip,  "released"
      pan_on := false
  return
  
   if (pan_on = true)
  {
      tooltip,  "XXXXXXXXEngage"
  }
  </code></pre>
  
  <p>The blocks which start with the "Rbutton " line are working
  correctly. The problem however is that the last block
   with the conditional statement is NEVER executed.
  Adding endless loop around last block or all the script
  doeas not help either.</p>
  
  <p>I am mostly familiar with such programming style (here using Python syntax):</p>
  
  <pre><code>pan_on = False
  while True:
      pan_on = False
      if key_down[Esc]:
          break
      if key_down[Rbutton]:
          pan_on = True
      if key_up[Rbutton]:
          pan_on = False
      ...
      if pan_on:
          draw_something ()
  </code></pre>
  
  <p>So I can't think of anything much defferent from that to 
  write a program, but seems that autohotkey is something
  "special" in this sense and one must use other approach?
  In the first AHK example it seems that "Rbutton::" is always in ready state and I think of it as a conditional "if key_down" inside a endless loop,
  but I must be wrond about it?</p>
  
  <p>So how do I make this  simple app, possibly without changing
  the code style?
  Where is the main loop in AHK? How does the control flow work, how
  to manage entry points for parts of code which is run?
  If I just write everything after "Rbutton::" it works but it 
  is not how one writes programs, and will be very difficult to 
  develop the logic further.</p>