AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

feature or bug

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Freighter



Joined: 07 Sep 2006
Posts: 64

PostPosted: Sun Feb 24, 2008 6:32 am    Post subject: feature or bug Reply with quote

this script works fine but it seems like it wouldn't considering the function POVChange doesn't have a global keyword saying anything about KeyToHoldDown1 or 2, is the function supposed to have access to this variable?

Code:
dup = w
ddown = s
dleft = a
dright = d

SetTimer, WatchPOV, 50
return


WatchPOV:
GetKeyState, POV, JoyPOV  ; Get position of the POV control.
KeyToHoldDownPrev1 = %KeyToHoldDown1% ; Prev now holds the key that was down before (if any).
KeyToHoldDownPrev2 = %KeyToHoldDown2%

; Some joysticks might have a smooth/continous POV rather than one in fixed increments.
; To support them all, use a range:
;first button
if POV < 0   ; No angle to report
   KeyToHoldDown1=
else if (POV >= 31500 or POV <= 4500)   ; 0 to 45 degrees: Forward
   KeyToHoldDown1 = %dup%
else if POV between 13500 and 22500  ; 135 to 225 degrees: Down
   KeyToHoldDown1 = %ddown%
else                                ; nothing
   KeyToHoldDown1 =

;secondaxis
if POV < 0   ; No angle to report
   KeyToHoldDown2=
else if POV between 4500 and 13500  ; 45 to 135 degrees: Right
   KeyToHoldDown2 = %dright%
else if POV >= 22500 ; 225 to 315 degrees: Left
   KeyToHoldDown2 = %dleft%
else                                ; nothing
   KeyToHoldDown2 =

if KeyToHoldDown1 <> %KeyToHoldDownPrev1%
   POVChange(1)
if KeyToHoldDown2 <> %KeyToHoldDownPrev2%
   POVChange(2)
return


POVChange(kn){
   SetKeyDelay -1  ; Avoid delays between keystrokes.
   KTHD := KeyToHoldDown%kn%
   KTHDP := KeyToHoldDownPrev%kn%
   ;msgbox % KeyToHoldDownPrev%kn%
   if KTHDP ; There is a previous key to release.
      Send, {%KTHDP% up}  ; Release it.
   if KTHD   ; There is a key to press down.
      Send, {%KTHD% down}  ; Press it down.
}
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2557
Location: Australia, Qld

PostPosted: Sun Feb 24, 2008 8:34 am    Post subject: Reply with quote

It's a feature.

AutoHotkey only maintains the global/local declaration lists while the script is being parsed. Since it is not known at run-time which variables were declared, double references are resolved in the following order:
  • Existing local variables.
  • Existing global variables.
  • New local or global variables, depending on the assume-mode of the function.

Edit: Found the documentation.
Quote:
Within a function, any dynamic variable reference such as Array%i% always resolves to a local variable unless no variable of that name exists, in which case a global is used if it exists. If neither exists and the usage requires the variable to be created, it is created as a local variable unless the assume-global mode is in effect.
Back to top
View user's profile Send private message
Freighter



Joined: 07 Sep 2006
Posts: 64

PostPosted: Fri Feb 29, 2008 5:22 am    Post subject: Reply with quote

thanks for the info
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group