This App is No Longer Maintained. Visit the Replacement at

StrokesPlus Forum
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
 All Forums
 Lua Scripts
 Action Scripts Using Alien
 TOGGLE MOUSE SPEED - is it possible?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List

* Forum Code is ON
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

Check here to subscribe to this topic.

T O P I C    R E V I E W
beholder Posted - 08/14/2012 : 21:08:59
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.
8   L A T E S T    R E P L I E S    (Newest First)
Rob Posted - 12/03/2012 : 17:25:42
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

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

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)
  return { names = names, offsets = offsets, types = types, size = off, new = struct_new,
	    byval = struct_byval }

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])
      error("field " .. key .. " does not exist")
  local function struct_set(_, key, val)
    if s_proto.offsets[key] then
      buf:set(s_proto.offsets[key] + 1, val, s_proto.types[key])
      error("field " .. key .. " does not exist")
  return setmetatable({}, { __index = struct_get, __newindex = struct_set,
			    __call = function () return buf 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"
      types[#types + 1] = "int"
  return unpack(types)

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

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)

-- ************ 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)
Rob Posted - 12/03/2012 : 16:53:49
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.
beholder Posted - 08/17/2012 : 16:31:41
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.
Rob Posted - 08/17/2012 : 09:45:26
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 =)
beholder Posted - 08/17/2012 : 08:27:51

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 
	iNewMouseSpeed = iSlowSpeed 
Rob Posted - 08/16/2012 : 17:49:55
I must say, this is a VERY useful script.

Thanks for the request!
Rob Posted - 08/16/2012 : 14:32:24
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'}

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 
	iNewMouseSpeed = iDefaultSpeed 


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.
Rob Posted - 08/14/2012 : 21:15:04
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)

StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000