This week in #MyoCraft, we're going to use the concept of "mouse clutch" as an excuse to play Counter Strike. Join me!

The problem with first person shooters is that you can keep turning left, spinning in a circle forever. Normally, when you run out of mouse pad you just lift the mouse up and move it back to the center. But what about when you are using a Myo armband and there is no way to raise it it off the ground? Enter the "mouse clutch":

  


scriptId = 'com.undercoveryeti.counterstrike'  
    scriptTitle = "Counter-Strike"  
    scriptDetailsUrl = "https://market.myo.com/app/551c4b7ee4b023b6f9cd9d62/"

    description = [[  
    Counter-Strike Script

    Play Counter Strike with your Myo armband! This lets you replace the mouse, you will still need your left hand on WASD.

    Questions or problems? Talk to us (@thalmicdev)  
    ]]

    link = [[ ]]

    controls = [[  
    Controls:  
     - Move arm to control mouse
     - Fist to shoot
     - Hold fingers spread to clutch mouse
     - Wave in to enable auto fire (hold fist to keep tapping shoot, for semis)
     - Hold wave out to hold right click (for good knifing)
     - Double tap to zoom
     ]]

    knownIssues = [[  
     - Only works on Windows
     ]]

    function notifyUser(edge)  
        if (edge == "down") then
            myo.notifyUserAction()
        end
    end  
     firing = false
    function shoot(edge)  
        notifyUser(edge)
        firing = edge == "down"
        myo.mouse("left",edge)
    end

    function clutch(edge)  
        myo.notifyUserAction()
        myo.controlMouse(edge == "up")
    end

    function zoom(edge)  
        notifyUser(edge)
        if (edge == "down") then
            myo.mouse("right","click")
        end
    end

    function knife(edge)  
        notifyUser(edge)
        myo.mouse("right",edge)
    end

    function previousWeapon(edge)  
        notifyUser(edge)
        myo.debug("Juuump " .. edge)
        if (edge == "down") then
            myo.keyboard("space", "press")
        end

    end

    function autoFire(edge)  
        if edge == "down" then
            autoFire = not autoFire
            autoFire = edge == "down"
            myo.vibrate("short")
            myo.vibrate("short")
            if autoFire then
                myo.vibrate("long")
            end
        end
    end

    function onPeriodic()  
        if (autoFire and firing) then
            myo.mouse("left", "click")
        end

    end

     STANDARD_BINDINGS = {
        fist            = shoot,
        fingersSpread   = clutch,
        waveOut         = knife,
        waveIn          = autoFire,
        doubleTap       = zoom
    }

    bindings = STANDARD_BINDINGS

    function onForegroundWindowChange(app, title)  
        app = string.lower(app)
        --myo.debug(app)

        return app == "csgo.exe" or app == "hl2.exe" or app == "hl.exe"

    end

    function activeAppName()  
        return scriptTitle
    end

    function onActiveChange(isActive)  
        myo.unlock("hold")
        myo.controlMouse(isActive)
        myo.mouse("left", "up");
        myo.mouse("right", "up");
    end

    function onPoseEdge(pose, edge)  
        --pose = conditionallySwapWave(pose)
        --myo.debug("onPoseEdge: " .. pose .. ": " .. edge)
        fn = bindings[pose]
        if fn then
            keyEdge = edge == "off" and "up" or "down"
            fn(keyEdge)
        end

        if (pose ~= "rest" and edge == "off") then
            timeSinceLastPose = myo.getTimeMilliseconds()
        end
    end

Grab the full script in the Myo Market.

This is using our extended function binding approach that we saw in the Adventure Games script. The key part of this script is when you hold the fingers spread pose, the mouse is disabled:



function clutch(edge)  
        myo.notifyUserAction()
        myo.controlMouse(edge == "up")
    end

So, if you find yourself holding your arm way out to the side, you just spread your fingers, move your arm back to the center, and relax your hand.

Counter-Strike

We call this a "clutch" because it's similar to how the clutch a car works. Pressing the clutch pedal on your car disconnects the engine from the gearbox, until you release it. Making the mouse clutch gesture in this script disconnects the Myo armband from the cursor, until you release it.

Why clutch instead of having a mouse control toggle like the mouse control script? It depends a lot on your use case. A toggle can be a bit simpler (you can do it with the Keyboard Mapper), but it then requires two gestures to recenter rather than one, which takes more time. That is not something you want to waste in a fast paced game like Counter-Strike. Since it's an active pose, it also makes it easy to get out of. At any point during your re-center, if you see a dude come into view you can just relax your hand and get full mouse control back. That can make all the difference.

I hope you have fun with this one! Let me know if you have a cool project you want to see featured on #MyoCraft.

Otherwise, see you next week!

Newsletter

Enter your email address and get all latest content delivered to your inbox every now and then.