This App is No Longer Maintained. Visit the Replacement at StrokesPlus.net

StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Active Topics
Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Lua Scripts
 Action Scripts Using Alien
 TOGGLE MOUSE SPEED - is it possible?
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

beholder

60 Posts

Posted - 08/14/2012 :  21:08:59  Show Profile
I also use AHK script for this. I have 2 speeds, one is default system setting (really fast) and another is the Gimp speed - really slow, speed literally cut to 1/2. Works really well, heavily useful feature.

Just wanted to know if it is possible to use one gesture to toggle the state of mouse speed from default to X and from X to default. One gesture, not twos.

Rob

USA
2615 Posts

Posted - 08/14/2012 :  21:15:04  Show Profile  Visit Rob's Homepage
I'm sure there's an API that can be called via Alien to handle that, but it will take a bit for me to get to.

(I'm experiencing some personal life things right now that are taking up all of my time)
Go to Top of Page

Rob

USA
2615 Posts

Posted - 08/16/2012 :  14:32:24  Show Profile  Visit Rob's Homepage
Try this:
local aliencore = alien.core
local user32 = aliencore.load("user32.dll")
local gSystemParametersInfoNoPointer = user32.SystemParametersInfoA
gSystemParametersInfoNoPointer:types{ ret = 'int', abi = 'stdcall', 'int', 'int', 'int', 'int'}
SPI_SETMOUSESPEED = 0x0071
SPIF_UPDATEINIFILE = 0x0001
SPIF_SENDWININICHANGE = 0x0002

local iSlowSpeed = 1 --Number from 1 to 20, 1 being slow, 20 being fast
local iDefaultSpeed = 8 --Number from 1 to 20, 1 being slow, 20 being fast

--Don't define iNewMouseSpeed as local anywhere, this lets the variable remain outside of this script

if iNewMouseSpeed == iDefaultSpeed then
	iNewMouseSpeed = iSlowSpeed 
else
	iNewMouseSpeed = iDefaultSpeed 
end

gSystemParametersInfoNoPointer(SPI_SETMOUSESPEED, nil, iNewMouseSpeed, SPIF_UPDATEINIFILE + SPIF_SENDWININICHANGE )

It will toggle between slow and normal speed. However, this first time iNewMouseSpeed isn't set to anything, so it will default to set the normal speed. You could always initialize iNewMouseSpeed with the exact setting Windows has in Global Lua, but I don't know if it's really worth it...just run the action once and it's ready to go.
Go to Top of Page

Rob

USA
2615 Posts

Posted - 08/16/2012 :  17:49:55  Show Profile  Visit Rob's Homepage
I must say, this is a VERY useful script.

Thanks for the request!
Go to Top of Page

beholder

60 Posts

Posted - 08/17/2012 :  08:27:51  Show Profile
LOVE THIS!!

I just had to turn around the switching logic because you are usually starting moving mouse with faster system default and on the 1st switch you want to have high-precision slow speed:

if iNewMouseSpeed == iSlowSpeed then
	iNewMouseSpeed = iDefaultSpeed 
else
	iNewMouseSpeed = iSlowSpeed 
end
Go to Top of Page

Rob

USA
2615 Posts

Posted - 08/17/2012 :  09:45:26  Show Profile  Visit Rob's Homepage
I initialized iNewMouseSpeed in Global Lua so it works as you described, however your solution is better as it doesn't require it to be initialized at all.

Yes, I do love this feature. While it's not something I use frequently since I'm a coder and not in Photoshop all day, it's invaluable when I do need some precise control and I can see how graphics people would pretty much not be able to live without it =)
Go to Top of Page

beholder

60 Posts

Posted - 08/17/2012 :  16:31:41  Show Profile
Moreover, you save you wrist from RSI by having mouse movement at top speed when precision is not needed. When you have fast mouse, only small movements are necessary to actually move it all the way across the screen which saves the space and your hand. And if you need precision, you can immediately go nuts with this feature.
Go to Top of Page

Rob

USA
2615 Posts

Posted - 12/03/2012 :  16:53:49  Show Profile  Visit Rob's Homepage
You can certainly set the values in the registry:
acRegistrySetString(3,"Control Panel\\Mouse","MouseSpeed","2", 1) 
acRegistrySetString(3,"Control Panel\\Mouse","MouseThreshold1","4", 1) 
acRegistrySetString(3,"Control Panel\\Mouse","MouseThreshold2","6", 1),
But I'm not sure if they take effect just by setting the values; I suspect you'd need to logoff/logon for the new settings to kick in. I've been unable to find a call/method to trigger this.

Now, it appears this is something which can be achieved via SystemParametersInfo (which is used to set the mouse speed), but I'm having difficulty setting up the param array within Lua in a way that the API call accepts. I keep getting a 0 return from SystemParametersInfo, indicating the call failed. I'm certain it's somehow due to the array not being received by the API.

Clearly there must be a way to do this, but I'm not certain how yet. Will keep looking around when I have some time.
Go to Top of Page

Rob

USA
2615 Posts

Posted - 12/03/2012 :  17:25:42  Show Profile  Visit Rob's Homepage
Ok, this seems to work:


Global Lua (you'll need to diff/merge the appropriate stuff from your current Global Lua with this code)
iSlowSpeed = 2 
iDefaultSpeed = 8 

function sp_before_action(gnm, gsx, gsy, gex, gey, gwd, gapp, gact)
  --not using this function for anything on my system
end

function sp_after_action(gnm, gsx, gsy, gex, gey, gwd, gapp, gact)
  --not using this function for anything on my system
end

aliencore = alien.core
alienstruct = alien.struct
user32 = aliencore.load("user32.dll")
kernel32 = aliencore.load("kernel32.dll")

function defstruct(t)
  local off = 0
  local names, offsets, types = {}, {}, {}
  for _, field in ipairs(t) do
    local name, type = field[1], field[2]
    names[#names + 1] = name
    off = math.ceil(off / aliencore.align(type)) * aliencore.align(type)
    offsets[name] = off
    types[name] = type
    off = off + aliencore.sizeof(type)
  end
  return { names = names, offsets = offsets, types = types, size = off, new = struct_new,
	    byval = struct_byval }
end

function struct_new(s_proto, ptr)
  local buf = aliencore.buffer(ptr or s_proto.size)
  local function struct_get(_, key)
    if s_proto.offsets[key] then
      return buf:get(s_proto.offsets[key] + 1, s_proto.types[key])
    else
      error("field " .. key .. " does not exist")
    end
  end
  local function struct_set(_, key, val)
    if s_proto.offsets[key] then
      buf:set(s_proto.offsets[key] + 1, val, s_proto.types[key])
    else
      error("field " .. key .. " does not exist")
    end
  end
  return setmetatable({}, { __index = struct_get, __newindex = struct_set,
			    __call = function () return buf end })
end

function struct_byval(s_proto)
  local types = {}
  local size = s_proto.size
  for i = 0, size - 1, 4 do
    if size - i == 1 then
      types[#types + 1] = "char"
    elseif size - i == 2 then
      types[#types + 1] = "short"
    else
      types[#types + 1] = "int"
    end
  end
  return unpack(types)
end


-- ************ SystemParametersInfo (No pointer for pvParam) ************

SPI_GETMOUSE = 0x0003
SPI_SETMOUSE = 0x0004
SPI_SETMOUSESPEED = 0x0071
SPIF_UPDATEINIFILE = 0x0001
SPIF_SENDWININICHANGE = 0x0002
SPIF_SENDCHANGE = SPIF_SENDWININICHANGE
gSystemParametersInfoNoPointer = user32.SystemParametersInfoA
gSystemParametersInfoNoPointer:types{ ret = 'int', abi = 'stdcall', 'int', 'int', 'int', 'int'}
function aSystemParametersInfoNoPointer(Action, Param, pParam, WinIni)
	return gSystemParametersInfoNoPointer(Action, Param, pParam, WinIni)
end

-- ************ SystemParametersInfo (With pointer for pvParam) ************

gSystemParametersInfo = user32.SystemParametersInfoW --Intentionally calling the wide version since 
                                                     --assigning two to the same DLL call causes problems
gSystemParametersInfo:types{ ret = 'int', abi = 'stdcall', 'int', 'int', 'pointer', 'int'}


-- ************ Define MOUSESPEED struct ************

MOUSESPEED = defstruct {
  { 'MouseThreshold1', 'long' },
  { 'MouseThreshold2', 'long' },
  { 'MouseSpeed', 'long' },
 }


Action Lua Script
--Instantiate the mouse speed struct/array
local aParams = MOUSESPEED:new()

--Populate the current values
gSystemParametersInfo(SPI_GETMOUSE, 0, aParams(), 0)

--Just for testing purposes, show each value
acMessageBox("Current MouseThreshold1: "..aParams.MouseThreshold1,"aParams.MouseThreshold1",nil)
acMessageBox("Current MouseThreshold2: "..aParams.MouseThreshold2,"aParams.MouseThreshold2",nil)
acMessageBox("Current MouseSpeed: "..aParams.MouseSpeed,"aParams.MouseSpeed",nil)

--Set new value(s) - (below were my preferred settings, fyi)
aParams.MouseThreshold1 = 6 --change as desired, or remove line
aParams.MouseThreshold2 = 10 --change as desired, or remove line
aParams.MouseSpeed = 1 --change as desired, or remove line

--Apply the new values
if gSystemParametersInfo(SPI_SETMOUSE, 0, aParams(), SPIF_SENDCHANGE) == 0 then
	--Show a message if the call fails
	acMessageBox("SPI_SETMOUSE Failed", "Returned 0", nil)
end
Go to Top of Page
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000