Skip to content

Instantly share code, notes, and snippets.

@NanoPi
Created August 24, 2014 05:47
Show Gist options
  • Select an option

  • Save NanoPi/315d6276c65291e0dfa2 to your computer and use it in GitHub Desktop.

Select an option

Save NanoPi/315d6276c65291e0dfa2 to your computer and use it in GitHub Desktop.
GlovePIE joystick mouse script
//pie.framerate = screen.RefreshRate
pie.framerate = 120
var.f = removeunits(pie.framerate)
var.x = deadzone(joy.X,0.03)
var.y = deadzone(joy.Y,0.03)
var.scale = 60
var.x = ensuremaprange(var.x,-1,1,-var.scale,var.scale)
var.y = ensuremaprange(var.y,-1,1,-var.scale,var.scale)
var.dial = EnsureMapRange(joy.dial, -0.62, 1, -1, 1)
//allow mouse movement by other means and update position if it moved
if [round(var.mx),round(var.my)] != mouse.CursorPos then
debug = [var.mx,var.my]
[var.mx,var.my] = mouse.CursorPos
endif
if pressed(joy.Button7) then
toggle(var.stickmode)
if var.stickmode == 0 then
//cursor1.Visible = false
//cursor2.Visible = false
//cursor3.Visible = false
//cursor4.Visible = false
else
//cursor1.Visible = true
//cursor2.Visible = true
//cursor3.Visible = true
//cursor4.Visible = true
endif
endif
if var.stickmode == 0 then
//floating point storage to improve slow movement. R button pressure slows more
//debug = [var.x/60,tan(var.x)] //
[var.x,var.y] = [tan(var.x),tan(var.y)] * (1800/var.f) /(var.dial*4+5)
//debug = [var.x,var.y] //
[var.mx,var.my] = [var.mx,var.my] + [var.x,var.y]
else
//cursor1.CursorPos = [var.mx-20,var.my]
//cursor2.CursorPos = [var.mx+20,var.my]
//cursor3.CursorPos = [var.mx,var.my-20]
//cursor4.CursorPos = [var.mx,var.my+20]
[key.up,key.down] = [deadzone(joy.y,0.35) < 0,deadzone(joy.y,0.35) > 0]
[key.left,key.right] = [deadzone(joy.x,0.35) < 0,deadzone(joy.x,0.35) > 0]
endif
//avoid moving the mouse to the same spot its already at
if [var.x,var.y] != [0,0] then mouse.cursorpos = [var.mx,var.my]
//debug = [var.mx,var.my] // behold the power of subpixels!
/*
GlovePIE specific: it is actually extremely important to set X and Y
positions in a SINGLE assignment command or line of code
good:
mouse.CursorPos = [var.mx,var.my]
good:
[mouse.CursorPosX,mouse.CursorPosY] = [var.mx,var.my]
bad:
mouse.CursorPosX = var.mx
mouse.CursorPosY = var.my
Q: why is it bad?
A: you will get a stair effect when moving diagonally
*/
// left click, middle click, right click
if pie.frame > 2 then // this check once covered up a bug when clicking RUN
press(mouse.leftbutton) = pressed(joy.Button1 or joy.slider>-0.5)
release(mouse.leftbutton) = released(joy.Button1 or joy.slider>-0.5)
endif
mouse.MiddleButton = joy.Button4
mouse.rightbutton = joy.Button3
// double click
if pressed(joy.Button2) then
press(mouse.LeftButton)
release(mouse.LeftButton)
press(mouse.LeftButton)
release(mouse.LeftButton)
endif
//[key.up,key.down] = [joy.Pov1up,joy.Pov1down]
//[key.left,key.right] = [joy.Pov1left,joy.Pov1right]
[key.up,key.down] = [joy.Button12,joy.Button11]
[key.left,key.right] = [joy.Button9,joy.Button10]
//[mouse.WheelUp,mouse.WheelDown]
//debug = [-deadzone(joy.r,0.35),deadzone(joy.r,0.35)*10]
var.cleft = deadzone(joy.z,0.35) < 0 and deadzone(joy.r,0.35) == 0
var.cright = deadzone(joy.z,0.35) > 0 and deadzone(joy.r,0.35) == 0
var.cup = deadzone(joy.r,0.35) < 0 and deadzone(joy.z,0.35) == 0
var.cdown = deadzone(joy.r,0.35) > 0 and deadzone(joy.z,0.35) == 0
mouse.wheelup = pressed(var.cup)
mouse.wheeldown = pressed(var.cdown)
if helddown(var.cup,0.25s) then var.w = 1
if helddown(var.cdown,0.25s) then var.w = -1
if var.w == 1 then
press(mouse.wheelup)
wait 50ms
endif
if var.w == -1 then
press(mouse.wheeldown)
wait 50ms
endif
if pressed(var.cup == 0 and var.cdown == 0) then var.w = 0
[key.ctrl+key.shift+key.tab,key.ctrl+key.tab] = [var.cleft,var.cright]
key.enter = joy.Button8
//key.backspace = joy.Button7
/*
using the 3in1 magic joybox from mayflash (PC035) without installing driver.
caution: holding the start button for 3 seconds changes modes in the hardware
Note for people unfamiliar with GameCube Controllers but who are
familiar with PS3, Xbox360 controls or PC gamepads with
analogue trigger buttons:
the L and R buttons are both analogue triggers and digital buttons.
you cannot press L and R digital buttons without pressing the triggers all the way.
L and R triggers have their own axes (DirectInput calls them Slider and Dial)
L and R triggers range from -1 (resting) to +1 (pressed)
there is an extra button (Z) above R but not L
when comparing ABXY on GameCube with ABXY on Xbox, X and B have swapped sides
GameCube does not have buttons under the analogue sticks
when mapping controls in some games, you have to hold L and R half-way
consequently, those games can't detect LT/RT until you press more than half-way
gamecube controls: triggered PC inputs in this script:
analog stick x = joy.x Mouse X
analog stick y = joy.y Mouse Y
dpad left = joy.Button9 Keyboard Left
dpad right = joy.Button10 Keyboard Right
dpad down = joy.Button11 Keyboard Down
dpad up = joy.Button12 Keyboard Up
c stick x = joy.z Keyboard CTRL+Tab or CTRL+Shift+Tab
c stick y = joy.r Mouse Scroll up + down
L pressure = joy.slider Mouse Left Click
R pressure = joy.dial Slows down Mouse X Y
button A = joy.Button1 Mouse Left Click
button B = joy.Button2 Mouse Double Left Click
button X = joy.Button3 Mouse Right Click
button Y = joy.Button4 Mouse Middle(ScrollWheel) Click
button L = joy.Button5 not bound
button R = joy.Button6 not bound
button Z = joy.Button7 switches modes (Left Stick + Arrow keys)
button Start = joy.Button8 Keyboard Enter/Return
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment