fttlov Nov 24, 2024 @ 10:45am
Wiimote as Mouse and Joystick Glovepie Script (WiiJoy)
Hello. I'd like to introduce a Glovepie Script for WiiMote.
Based on script by "lednerg" fixed for Windows 10/11 with properly working function from me -auto-centering axis and extra buttons
Examples of use:
- Wiimote (MotionPlus) as mouse
- Real Gamepad emulation: use nunchuck as left stick, Wiimote as right stick (ppjoy* virtual axis) with auto-centering like a real gamepad stick.
- Switching in game between the first two modes using hotkeys! See "Alt. method" in the script
- Real mouse can be used as axis* with auto-centering for flight, racing games or something else

*PPJoy - app to create virtual Gamepad. All commands from real devices (mouse, keyboard, wiimote .etc) translate to one virtual device.
Important: PPjoy and Glovepie use Windows old "dinput" method. Modern games use "xinput" (Xbox like Pad) instead and we need dinput to xinput translator like a "x360ce"

How it look like for FPS (first thing that came up on youtube):
https://www.youtube.com/watch?v=UVfJuuVmZNI
Any axis, button or value can be customized. All important notes and settings are annotated inside the script.

What is needed:
Glovepie [github.com] for interpretation wii command to windows directinput.

PPJoy [github.com]
Virtual joystick. Unfortunately, for use on x64 system need to disable driver signature, because driver is not signed by developer. In bios disable secure boot, then open cmd console with admin priv., put "bcdedit /set testsigning on" without quotes, enter and restart.
Install ppjoy, start "Configure Joystick.exe", add button - add joystick, mapping button - next - next - next - ok.

Connect Wiimote with standard microsoft bluetooth driver without pairing pin:
Windows 10 settings-Bluetooth&Devices-More Devices and printer settings(at the very bottom)-add device-1+2 wii button to pair.
Open Glovepie and put this script:
/* Wiimote MotionPlus Mouse Joystick script with auto-centering axis Examples of use: - Wiimote (MotionPlus) as mouse - Real Gamepad emulation: use nunchuck as left stick, Wiimote as right stick (ppjoy* virtual axis) with auto-centering like a real gamepad stick. - Switching in game between the first two modes using hotkeys! See "Alt. method" in the script - Real mouse can be used as axis* with auto-centering for flight, racing games or something else About var.Mouse: 0 or 1 value below depends on how the developer implements controls in the game. For example in FPS games: In most of Unreal and Cryengine games, mouse and joystick work simultaneously, use var.Mouse = 0. In Dying Light mouse not work simultaneously with gamepad input and you can't walk by gamepad stick and look by mouse (real or wiimote). Use var.Mouse = 1 and Wiimote will control virtual (ppjoy) gamepad axis (right stick). Troubleshooting: - When you run the script, Wiimote should be stationary on a horizontal surface a couple of seconds for calibration - Timer problem on Windows 10/11 for old games. If you see microstutter when you looking left-right in game (even with VSYNC, Freesync .etc), Google: GlobalTimerResolutionRequests - Right click Windows Start button - run: joy.cpl - to test ppjoy -Glovepie-TroubleShotter-No auto bluetooth connect if connecting problem */ PIE.FrameRate = 120hz //frequency of script execution (60hz monitor refresh rate x2) var.Mouse = 0 // 0 - Wiimote control mouse cursor, 1 - Wiimote control fake right stick, mouse off. // Alt. method to switching var.Mouse between 0 - 1 by pressing buttons when script is active // - comment var.Mouse variable above to activate this method. Bind any key(s) and time (to prevent random pressing) on wii, keyboard etc. if Helddown(Keyboard.F4, 250ms) { // pressed F4 250ms to switch //if Helddown(Wiimote.down, 250ms) + pressed(Wiimote.A) { //while Wiimote Down is pressed 250ms, press Wiimote A to switch toggle var.Mouse } var.RealMouse = 0 // 1 - Control ppjoy axis fake stick by REAL mouse, 0 - off //RealMouse not work with var.Mouse = 1 simultaneously // set Virtual Gamepad (ppjoy) "fake" stick sensitivity. Lower - faster var.sensitivityX = 275 //X axis sensitivity var.sensitivityY = 275 //Y axis sensitivity //Autocentering "fake" stick. Lower - faster var.autocenterspeed = 92/100 //how fast "fake stick" return to center. 100/100 - no autocentering //Wii Moution Plus mouse settings. No effect to control ppjoy axis var.Speed = 85 //Wiimote mouse cursor sensitivity. Higher - faster var.HoldToMove = True //Map physical button to function var.MoveButton = Wiimote.down //Hold to Move mouse cursor / ppjoy axis //var.MoveButton = Wiimote.Nunchuk.CButton /* When pressed, these buttons slow down or speed up movement. See belown in script: var.YawSpeed = wiimote.MotionPlus.YawSpeed * 2 - x2 speed up movement var.YawSpeed = wiimote.MotionPlus.YawSpeed / 6 - x6 slow down movement You can change the values or comment //var.Fire(Zoomm)Button to disable that function */ var.FireButton = Wiimote.B //Fire. More accuracy when pressing, 6x slower now var.ZoomButton = Wiimote.A //Aiming button in FPS Games // Code. Don't touch if you don't know what you're doing if var.RealMouse = 1 var.deltaX = delta(realmouse.DirectInputX) / var.sensitivityX var.deltay = delta(realmouse.DirectInputY) / var.sensitivityY else var.deltax = delta(var.StickX) / var.sensitivityX var.deltay = delta(var.StickY) / var.sensitivityY } // Joystick maprange for fullhd, Perhaps need to change change for other resolutions var.JoyXMax = 4 var.JoyXMin = -4 var.JoyYMax = 4 var.JoyYMin = -4 IF HeldDown(abs(wiimote.SmoothRoll)>135, 1 second) THEN var.WiimoteUpsideDown = true ELSE var.WiimoteUpsideDown = false IF var.HoldToMove = true { var.Move = var.MoveButton ELSE IF var.MoveButton = false AND var.WiimoteUpsideDown = false THEN var.Move = true ELSE var.Move = false } if wiimote.HasMotionPlus = false then debug = "WiiMotion Plus NOT DETECTED!" //if Wiimote.HasNunchuk then Nunchuk.Calibrated = False else Nunchuk.Calibrated = True if Wiimote.HasNunchuk then Nunchuk.Calibrated = False IF wiimote.HasMotionPlus = true AND var.Move = true { var.YawSpeed = wiimote.MotionPlus.YawSpeed var.PitchSpeed = wiimote.MotionPlus.PitchSpeed if helddown(var.ZoomButton, 1ms) { var.YawSpeed = wiimote.MotionPlus.YawSpeed * 2 // Zoom Button x2 more speed var.PitchSpeed = wiimote.MotionPlus.PitchSpeed * 2 // Zoom Button x2 more speed } if helddown(var.FireButton, 1ms) { var.YawSpeed = wiimote.MotionPlus.YawSpeed / 6 //Fire Button x6 less speed var.PitchSpeed = wiimote.MotionPlus.PitchSpeed / 6 //Fire Button x6 less speed } if helddown(var.ZoomButton, 1ms) and helddown(var.FireButton, 1ms) { var.YawSpeed = wiimote.MotionPlus.YawSpeed / 6 //Zoom & Fire Button x6 less speed var.PitchSpeed = wiimote.MotionPlus.PitchSpeed / 6 //Zoom & Fire Button x6 less speed } if SameValue( Smooth(wiimote.SmoothRoll, 10), wiimote.SmoothRoll, 10) then var.SmoothRoll = Smooth(wiimote.SmoothRoll, 10) else var.SmoothRoll = wiimote.SmoothRoll if var.Roll < 0 and var.Roll >= -90 { var.XYswap = 1 - EnsureMapRange(var.Roll, -90, 0, 0, 1) var.RightDown = -1 var.TopUp = 1 } if var.Roll <= 90 and var.Roll >= 0 { var.XYswap = 1 - EnsureMapRange(var.Roll, 90, 0, 0, 1) var.RightDown = 1 var.TopUp = 1 } if var.Roll > 90 and var.Roll <= 180 { var.XYswap = 1 - EnsureMapRange(var.Roll, 90, 180, 0, 1) var.RightDown = 1 var.TopUp = -1 } if var.Roll < -90 and var.Roll >= -180 { var.XYswap = 1 - EnsureMapRange(var.Roll, -90, -180, 0, 1) var.RightDown = -1 var.TopUp = -1 } var.SpeedX = var.TopUp * var.YawSpeed - ( var.TopUp * var.YawSpeed * var.XYswap ) + ( var.RightDown * var.PitchSpeed * var.XYswap ) var.SpeedY = var.TopUp * var.PitchSpeed - ( var.TopUp * var.PitchSpeed * var.XYswap) + ( -var.RightDown * var.YawSpeed * var.XYswap ) if var.Mouse = 0 { // In alt. method 0 - script start as Wiimouse, 1 - fake stick. fakemouse.DirectInputX = int(var.MouseX) // Can try = smooth(int(var.MouseY) but adds a huge delay fakemouse.DirectInputY = int(var.MouseY) // Can try = smooth(int(var.MouseY) but adds a huge delay var.MouseX = var.MouseX + ( var.SpeedX / (10500000 - EnsureMapRange(var.Speed, 0, 100, 0, 10000000) ) ) var.MouseY = var.MouseY - ( var.SpeedY / (10500000 - EnsureMapRange(var.Speed, 0, 100, 0, 10000000) ) ) else var.JoyX += var.SpeedX var.JoyY -= var.SpeedY var.StickX = MapRange(var.JoyX, var.JoyXMin, var.JoyXMax, -1, 1) var.StickY = MapRange(var.JoyY, var.JoyYMin, var.JoyYMax, -1, 1) } } if var.MoveButton = false { var.MouseX = fakemouse.DirectInputX var.MouseY = fakeMouse.DirectInputY } // Bind Wiimote to Axis PPJoy.Analog0 = deadzone(Wiimote.Nunchuk.JoyX, 1.5%) // Left stick X axis, can change deadzone in "%" PPJoy.Analog1 = -deadzone(Wiimote.Nunchuk.JoyY, 1.5%) // Left stick Y axis ("= -deadzone" to invert axis ) //Next 2 axis with autocentering. Remap axis while keep logical numbering if abs(ppjoy.Analog2) >= 0 and abs(ppjoy.Analog3) >= 0 {// duno how it work, but it is.. PPJoy.Analog2 = PPJoy.Analog2 * var.autocenterspeed + var.deltax // Right stick X axis emulation. "+var.deltax" normal axis PPJoy.Analog3 = PPJoy.Analog3 * var.autocenterspeed - var.deltay // Right stick Y axis emulation. "-var.deltay" invert axis } //Button Mapping PPJoy.Digital0 = Wiimote1.Up //Button 1 PPJoy.Digital1 = Wiimote1.Left //Button 2 PPJoy.Digital2 = Wiimote1.Right //Button 3 PPJoy.Digital3 = Wiimote1.Down //Button 4 ppjoy.Digital4 = Wiimote.1 //Button 5 ppjoy.Digital5 = Wiimote.2 //Button 6 ppjoy.Digital6 = Wiimote.Home //Button 7 ppjoy.Digital7 = Wiimote.Minus //Button 8 ppjoy.Digital8 = Wiimote.Plus //Button 9 ppjoy.Digital9 = Wiimote.A //Button 10 ppjoy.digital10 = Wiimote.B //Button 11 ppjoy.Digital11 = Wiimote.Nunchuk.Z //Button 12 ppjoy.Digital12 = Wiimote.Nunchuk.C //Button 13 //Extra buttons ppjoy.Digital13 = -Nunchuk.RelAccZ > 16 //Button 14 //nunchuck gyro (nunchuck move like a blow hammer to release button, for melee attack etc.) //ppjoy.Digital14 = Nunchuk.Roll < -55 //Button 15 //nunchuck accel (clockwise(anti) hand on 55 degrees to release button) //ppjoy.Digital14 = Wiimote.Nunchuk.Pitch > 75 //Button 1x //ppjoy.Digital14 = Wiimote.Nunchuk.Pitch < -15 //Button 1x //ppjoy.Digital14 = Wiimote.Nunchuk.Roll > 65 //Button 1x //ppjoy.Digital14 = HeldDown(Wiimote.Minus, 10ms) + Wiimote.Nunchuk.C =true //ppjoy.Digital14 = Wiimote.Nunchuk.Z or HeldDown(Wiimote.Nunchuk.JoyY < -0.96, 100ms) //ppjoy.Digital15 = Helddown(Wiimote.A, 100ms) + DoubleClicked(Wiimote.Nunchuk.C) //ppjoy.Digital15 = DoubleClicked(Wiimote.Nunchuk.C) //if -Wiimote.Nunchuk.JoyY > 0.97 then press Keyboard.Shift else release Keyboard.Shift //if HeldDown(Wiimote.Minus, 10ms) and -Wiimote.Nunchuk.JoyX > 0.40 { // press Mouse.WheelUp // wait 400ms // release Mouse.WheelUp //} //if HeldDown(Wiimote.Minus, 10ms) and Wiimote.Nunchuk.JoyX > 0.40 { // press Mouse.WheelDown // wait 400ms // release Mouse.WheelDown //} //Keyboard.Shift = HeldDown(Wiimote.plus, 200ms) //Keyboard.BackSpace = wiimote.RelAccY > 30 //Keyboard.M = DoubleClicked(Wiimote.Minus) //Keyboard.M = Wiimote.1 //Keyboard.LeftControl = Wiimote.A //Keyboard.I = HeldDown(Wiimote.Minus, 150ms) //Mouse.LeftButton = Wiimote.B //Mouse.RightButton = Wiimote.A //Mouse.MiddleButton = //ppjoy.Digital15 = DoubleClicked(Mouse.LeftButton) //Battery status // Very Inaccurate indicator var.Batt = wiimote.Battery / 48 //if wiimote.1 + wiimote.2 = true { Debug = "Battery at " + wiimote.Battery /1.4 // debug = "Battery level: " + 100*48*var.Batt/192 + "%" //alternative method //else // Debug ="" //} //Enable (Disable) leds (at the time of callibration led2 & led3 be on, after sucсsessful calibration - led1). Wiimote.Led1 = True Wiimote.Led2 = false Wiimote.Led3 = false Wiimote.Led4 = false
Glovepie-CP Settings-Joystick to make sure it works.
Glovepie-TroubleShotter-No auto bluetooth connect if connecting problem

*For emulate xbox controller get any dinput (GlovePIE) to xinput (Xbox controller) translator, i use
x360ce [www.x360ce.com]
Download 4.x version and follow the instructions on site below. Map button and axis. In this case for left trigger axis 1 and 2, right trigger - 3 and 6. Invert axis depends on each game.
Last edited by fttlov; Apr 29 @ 7:25am
< >
Showing 1-2 of 2 comments
rawWwRrr Nov 24, 2024 @ 10:52am 
Why hide the code in spoiler?
fttlov Nov 24, 2024 @ 11:04am 
Fixed
< >
Showing 1-2 of 2 comments
Per page: 1530 50

Date Posted: Nov 24, 2024 @ 10:45am
Posts: 2