Jump to content

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

Kind of rotary switch with a joystick axis


  • Please log in to reply
19 replies to this topic
VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
The variables j%A_LoopField% and p%A_LoopField% each contain an integer in the range of [1, %A_LoopField%NumberOfRanges]. They are used to determine when to send a key, and which key to send. To restrict an axis based on the number of ranges, try the following method.
VUpKey = !+{Insert} ; SHF+ALT+INSERT

VDownKey = !+{PgUp} ; SHF+ALT+PGUP

VNumberOfRanges = 3 ; how many 'steps' do we want the V axis to have between 0 and 100

; restrictions don't need to be specified is not desired for an axis



UUpKey = +{Right} ; SHF+RIGHT

UDownKey = +{Left} ; SHF+LEFT

UNumberOfRanges = 21 ; how many 'steps' do we want the U axis to have between 0 and 100

UUpperRestriction = 1 ; the uppermost 'step' will not be counted

ULowerRestriction = 9 ; the lowermost 9 'steps' will not be counted



Axis = VU ; these are the axises we're using

JoyNum = 2 ; put a number if you have more than 1 joystick

; WARNING: no newbies below this line

#Persistent

SendMode, Input ; es muy rapido

SetTimer, WatchAxis, 10

WatchAxis:

Loop, Parse, Axis ; Sets the variable A_LoopField to the current axis

If (p%A_LoopField% != j%A_LoopField% := Floor(1 + (GetKeyState(joynum

. "Joy" . A_LoopField, "P") * %A_LoopField%NumberOfRanges - 1 ) / 100))

{

	Dir := (p%A_LoopField% < j%A_LoopField%) * 2 - 1

   If (p%A_LoopField% = "")

	p%A_LoopField% := j%A_LoopField%

	Else	If ( p%A_LoopField% > %A_LoopField%LowerRestriction

		&& p%A_LoopField% + Dir > %A_LoopField%LowerRestriction )

		&& ( %A_LoopField%NumberOfRanges - p%A_LoopField% >= %A_LoopField%UpperRestriction

		&& %A_LoopField%NumberOfRanges - p%A_LoopField% - Dir >= %A_LoopField%UpperRestriction )

		   Send % "{Blind}" . (Dir>0 ? %A_LoopField%UpKey : %A_LoopField%DownKey)

   p%A_LoopField% += Dir

}

return


flyway
  • Guests
  • Last active:
  • Joined: --
This is awesome man. You're a star.
Will test it tonight and back here for a feedback.

Thanks alot and again and again and again.

flyway
  • Guests
  • Last active:
  • Joined: --
[VxE],

It's seemed not working properly when using boundaries limitations and can't tell you why right now. Need to test it further.
If not using Upper/Lower Restrictions seemed that something in behavior was different from simply deleting those lines and keeping them but equaling them to zero.
Anyway am still wondering if this method of counting steps to be out of action will do the trick I need. Maybe am wrong here or not seeing all picture, but I need to have the full number o steps within the limited range of that (each) axis, see?
Ex: Vaxis, I need 32steps but got to have them within 5% - 95% of that axis values. Hope you understood me.
This is why had pointed to a limitation in axis value instead of cutting out some of the steps in both ends.

Thanks once more.

VxE
  • Moderators
  • 3622 posts
  • Last active: Dec 24 2015 02:21 AM
  • Joined: 07 Oct 2006
Hmm... while there's no 'real' way to actually limit the axis itself, if you need to have 32 steps that don't include the top/bottom ~5% of the axis, then just set the number of ranges to 36 and give it a limit of 2 on each side.

Of course, you're always welcome to tweak my code to suit your needs.

flyway
  • Guests
  • Last active:
  • Joined: --

Hmm... while there's no 'real' way to actually limit the axis itself, if you need to have 32 steps that don't include the top/bottom ~5% of the axis, then just set the number of ranges to 36 and give it a limit of 2 on each side.


Yep, guess it's same thing and it'll do the trick.
Thanks alot my friend.

Of course, you're always welcome to tweak my code to suit your needs.


Now, this will impossible for me... :D

Cheers.