It is currently Thu Oct 19, 2017 4:01 pm



Reply to topic  [ 8 posts ] 
 Multiple Toggles in a script. Possible? 
Author Message
One Eyed Hopeful
User avatar

Joined: Thu Jul 13, 2017 10:06 am
Posts: 23
Location: Rio de Janeiro
Reply with quote
Sorry to bother you, guys... today I got some time so I'm trying to understand better what can I do with FreePIE.

I need to implement two toggles in my script, one which alternate from an auto-centering or not-auto-centering mouse, the other which copy my mouse movements to another vJoy.
So far, I have the first one as this:

Code:
##############################################
# toggle relative mouse
##############################################

toggle = keyboard.getKeyDown(Key.LeftShift) and keyboard.getPressed(Key.Space)

if toggle:
    enabled = not enabled


##############################################
# relative mouse (auto centering when idle)
##############################################

if (enabled):
   a += mouse.deltaX
   b += mouse.deltaX
   if filters.stopWatch(True,600):
      c = a + 0
   
   if filters.stopWatch(True,30):
      d = b + 0

   if (c - d == 0):
      if mx < -500:
         mx += rm_speed
      elif mx > 500:
         mx -= rm_speed
      if my < -500:
         my += rm_speed
      elif my > 500:
         my -= rm_speed


How can I define a second toggle without mess with the already functional?


Fri Jul 14, 2017 5:20 pm
Profile WWW
One Eyed Hopeful
User avatar

Joined: Thu Jul 13, 2017 10:06 am
Posts: 23
Location: Rio de Janeiro
Reply with quote
Something i do not understand is why the following code do not work:

Code:
# Switch HeadLook with mouse
if keyboard.getKeyDown(Key.LeftShift) and keyboard.getPressed(Key.W):
   vJoy[2].x = mx
   vJoy[2].y = my
else:
   vJoy[2].x = kx
   vJoy[2].y = ky


I already implemented many switches like that and all of them works...


Fri Jul 14, 2017 5:25 pm
Profile WWW
One Eyed Hopeful

Joined: Tue Jul 11, 2017 1:49 pm
Posts: 7
Reply with quote
So is this a code to autocenter the mouse, it's actually what i'm looking for (made a topic about it a few days ago)

Anyway I think this is the same problem as in your other post, for some reason 'if' statements don't work if you press a key and then want an action to be followed by something that is connected through freepie, like a joystick. It does seem to work for the other way around though, like if you press a button on the joystick and then want the mouse to do something.

As for the toggle, wouldn't it be possible make a variable called secondtoggle, toggle seems to be variable since it isn't in the command list . Or make some sort of different loop (like I said, all very new at this stuff)

If I may ask , if I would want to autocenter the mouse without the idle timer any idea what I would need to write?


Fri Jul 14, 2017 6:12 pm
Profile
One Eyed Hopeful
User avatar

Joined: Thu Jul 13, 2017 10:06 am
Posts: 23
Location: Rio de Janeiro
Reply with quote
Well, my script currently has three mode of mouse centering:

Hard centering, Auto-centering and, something I'm very proud of, a smart-centering when the cursor is near the center.

My mouse is defined this way:

Code:

if starting:
   relativemouse = True
   max      =  Int16.MaxValue*0.5+2
   min       = -Int16.MaxValue*0.5+1
   mx         = 0
   my         = 0
   a       = 0
   b       = 0
   c       = 0
   d       = 0
    sensitivity = 35
   speed = 10                     # auto-centering speed
   pradius = 1200                          # auto-centering radius
   nradius = pradius - (pradius *2)                           # negative range radius, self defined
   rm_speed = 250                  # relative mouse speed

# pitch
my += mouse.deltaY * sensitivity
# yaw
mx += mouse.deltaX * sensitivity


Than, here are the three implementations I use:

Code:

# Manual centering
if keyboard.getKeyDown(Key.LeftControl):
  mx = 0
  my = 0

##############################################
# Smart-centering when the mouse is close to the center, inside a predefined radius
##############################################
if (mx < pradius) and (mx > 0):
   mx = mx - speed
elif (mx > nradius) and (mx < 0):
   mx = mx + speed

if (my < pradius) and (my > 0):
   my = my - speed
elif (my > nradius) and (my < 0):
   my = my + speed

##############################################
# toggle relative mouse
##############################################

toggle = keyboard.getKeyDown(Key.LeftShift) and keyboard.getPressed(Key.Space)

if toggle:
    relativemouse = not relativemouse


##############################################
# relative mouse (auto centering when idle)
##############################################

if (relativemouse):
   a += mouse.deltaX
   b += mouse.deltaX
   if filters.stopWatch(True,600):
      c = a + 0
   
   if filters.stopWatch(True,30):
      d = b + 0

   if (c - d == 0):
      if mx < -500:
         mx += rm_speed
      elif mx > 500:
         mx -= rm_speed
      if my < -500:
         my += rm_speed
      elif my > 500:
         my -= rm_speed


##############################################
# Mouse to vJoy
##############################################

vJoy[1].x = filters.deadband(mx, 10)
vJoy[1].y = filters.deadband(my, 10)


Hope this helps!


Fri Jul 14, 2017 9:49 pm
Profile WWW
One Eyed Hopeful

Joined: Tue Jul 11, 2017 1:49 pm
Posts: 7
Reply with quote
many thanks, I have been begging the internet for this

Tomorrow I'll try to wrap my head around it:)

and good luck in elite dangerous, I've been playing that a lot when it released but I can't stomach it in VR


Fri Jul 14, 2017 10:04 pm
Profile
One Eyed Hopeful
User avatar

Joined: Thu Jul 13, 2017 10:06 am
Posts: 23
Location: Rio de Janeiro
Reply with quote
Thanks to you too, you are welcome!

Here it is my current full script, for references:

Code:
from System import Int16

if starting:
   system.setThreadTiming(TimingTypes.HighresSystemTimer)
   system.threadExecutionInterval = 5 # loop delay
   relativemouse = True
   headlook = False
   joystick[0].setRange(0, 2048)
   max      =  Int16.MaxValue*0.5+2
   min       = -Int16.MaxValue*0.5+1
   mx         = 0
   my         = 0
   jx       = 0
   jy       = 0
   kx       = 0
   ky       = 0
   hx       = 0
   hy       = 0
   hmx       = 0
   hmy       = 0
   a       = 0
   b       = 0
   c       = 0
   d       = 0
    sensitivity = 35
   speed = 10                     # auto-centering speed
   pradius = 1200                  # auto-centering radius
   nradius = pradius - (pradius *2)   # negative range radius
   rm_speed = 250                  # relative mouse speed
   
##############################################
# Mouse setup   
##############################################

# pitch
my += mouse.deltaY * sensitivity
# yaw
mx += mouse.deltaX * sensitivity

if (mx > max):
  mx = max
elif (mx < min):
  mx = min

if (my > max):
  my = max
elif (my < min):
  my = min

##############################################
# Manual centering
# Useful when switching virtual desktops
##############################################

if keyboard.getKeyDown(Key.LeftControl):
  mx = 0
  my = 0


##############################################
# Auto-centering if close to the center
##############################################

if (mx < pradius) and (mx > 0):
   mx = mx - speed
elif (mx > nradius) and (mx < 0):
   mx = mx + speed

if (my < pradius) and (my > 0):
   my = my - speed
elif (my > nradius) and (my < 0):
   my = my + speed


##############################################
# toggle relative mouse
##############################################

toggle = keyboard.getKeyDown(Key.LeftShift) and keyboard.getPressed(Key.Space)

if toggle:
    relativemouse = not relativemouse


##############################################
# relative mouse (auto centering when idle)
##############################################

if (relativemouse):
   a += mouse.deltaX
   b += mouse.deltaX
   if filters.stopWatch(True,600):
      c = a + 0
   
   if filters.stopWatch(True,30):
      d = b + 0

   if (c - d == 0):
      if mx < -500:
         mx += rm_speed
      elif mx > 500:
         mx -= rm_speed
      if my < -500:
         my += rm_speed
      elif my > 500:
         my -= rm_speed


##############################################
# Mouse to vJoy
##############################################

vJoy[1].x = filters.deadband(mx, 10)
vJoy[1].y = filters.deadband(my, 10)


##############################################
# G13 Joystick
##############################################

# Apply curves to axis
jx = Roll.getY(joystick[0].x)
jy = joystick[0].y

#vJoy[0].x = filters.mapRange(jx, 0, 2048, -Int16.MaxValue, Int16.MaxValue)
#vJoy[0].y = filters.mapRange(jy, 0, 2048, -Int16.MaxValue, Int16.MaxValue)
vJoy[0].x = jx
vJoy[0].y = jy


##############################################
# Keyboard to Joystick
# For Headlook movements and macros
##############################################

if keyboard.getKeyDown(Key.LeftControl) and keyboard.getPressed(Key.NumberPad5):
   kx = 0
   ky = 0

# Directional movements, with small increments
if keyboard.getKeyDown(Key.LeftControl) and keyboard.getPressed(Key.NumberPad4): # left
   kx = kx -2000
if keyboard.getKeyDown(Key.LeftControl) and keyboard.getPressed(Key.NumberPad6): # right
   kx = kx +2000
if keyboard.getKeyDown(Key.LeftControl) and keyboard.getPressed(Key.NumberPad2): # down
   ky = ky -2000
if keyboard.getKeyDown(Key.LeftControl) and keyboard.getPressed(Key.NumberPad8): # up
   ky = ky +2000
if keyboard.getKeyDown(Key.LeftControl) and keyboard.getPressed(Key.NumberPad1): # left/down
   keyboard.getKeyDown(Key.LeftControl) and keyboard.setPressed(Key.NumberPad4)
   keyboard.getKeyDown(Key.LeftControl) and keyboard.setPressed(Key.NumberPad2)
if keyboard.getKeyDown(Key.LeftControl) and keyboard.getPressed(Key.NumberPad7): # left/up
   keyboard.getKeyDown(Key.LeftControl) and keyboard.setPressed(Key.NumberPad4)
   keyboard.getKeyDown(Key.LeftControl) and keyboard.setPressed(Key.NumberPad8)
if keyboard.getKeyDown(Key.LeftControl) and keyboard.getPressed(Key.NumberPad3): # right/down
   keyboard.getKeyDown(Key.LeftControl) and keyboard.setPressed(Key.NumberPad6)
   keyboard.getKeyDown(Key.LeftControl) and keyboard.setPressed(Key.NumberPad2)
if keyboard.getKeyDown(Key.LeftControl) and keyboard.getPressed(Key.NumberPad9): # right/up
   keyboard.getKeyDown(Key.LeftControl) and keyboard.setPressed(Key.NumberPad6)
   keyboard.getKeyDown(Key.LeftControl) and keyboard.setPressed(Key.NumberPad8)

# Panel shows up and close when keys releases
# Target panel
if keyboard.getKeyDown(Key.LeftShift) and keyboard.getPressed(Key.A): # Target Panel
   kx = -12500
   ky = -2100
if keyboard.getKeyUp(Key.LeftShift) and (kx == -12500):
   kx = 0
   ky = 0

# System panel
if keyboard.getKeyDown(Key.LeftShift) and keyboard.getPressed(Key.D): # System Panel
   kx = 12500
   ky = -2100
if keyboard.getKeyUp(Key.LeftShift) and (kx == 12500):
   kx = 0
   ky = 0

# Role panel
if keyboard.getKeyDown(Key.LeftShift) and keyboard.getPressed(Key.S): # Role Panel
   kx = 0
   ky = -11500
if keyboard.getKeyUp(Key.LeftShift) and (ky == -11500):
   kx = 0
   ky = 0


##############################################
# Filtering the headlook axis
##############################################

hx = filters.deadband((mx / 3), 20)
hy = filters.deadband((filters.mapRange((my / 3), -100, 100, 100, -100)), 20)


##############################################
# Momentary switch for Mouse HeadLook
##############################################

if keyboard.getKeyDown(Key.LeftShift) and keyboard.getKeyDown(Key.W):
   #headlook = not headlook
   vJoy[2].x = hx
   vJoy[2].y = hy
else:
   vJoy[2].x = kx
   vJoy[2].y = ky


##############################################
# toggle Mouse Headlook
##############################################

#toggle = joystick[0].getPressed(0)

#if toggle:
#   headlook = not headlook
#   vJoy[2].x = kx
#   vJoy[2].y = ky

#if (headlook):
#   headlook = headlook
#   vJoy[2].x = (hx / 2)
#   vJoy[2].y = (hy / 2)
   

##############################################
# Debug informations
##############################################

# Joystick
diagnostics.watch(vJoy[0].x)
diagnostics.watch(vJoy[0].y)

# Mouse
diagnostics.watch(vJoy[1].x)
diagnostics.watch(vJoy[1].y)

# Keyboard
diagnostics.watch(vJoy[2].x)
diagnostics.watch(vJoy[2].y)

# Headlooks
#diagnostics.watch(hx)
#diagnostics.watch(hy)

# Toggles
diagnostics.watch(relativemouse)
diagnostics.watch(headlook)



All the best!


Fri Jul 14, 2017 10:11 pm
Profile WWW
One Eyed Hopeful

Joined: Thu Oct 03, 2013 7:10 am
Posts: 32
Reply with quote
About relative move:

read that

http://www.mtbs3d.com/phpBB/viewtopic.php?f=139&t=22204&p=162391#p162364


Sat Jul 15, 2017 1:24 am
Profile
One Eyed Hopeful

Joined: Mon Feb 10, 2014 4:48 am
Posts: 46
Reply with quote
i don't know if this has been answered but "toggle" is just a defined variable as long as you use different names (for instance: toggle_mousetoJystick or toggle_haedtracking) and the correct if cycle after them. you can have as many as you want


Wed Aug 16, 2017 4:10 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by STSoftware.