Home
Download
Screenshots

Wiki
Plugins
Translations
Developers
Donate

Forums/Help
Contact Us

StrokeIt

Lua Scripts for upcoming StrokeIt .9.7 "enhanced" version

Posted by Leo 
Leo
Lua Scripts for upcoming StrokeIt .9.7 "enhanced" version
December 15, 2009 03:22AM
Scott's volume script for WinXP, win2000 server

-- Author: Scott D. Barker
-- Email: sdbarker[add]gmail.com
-- File: volume.lua
-- Version: 0.1a
--
-- Description:
-- StrokeIt Lua script to change the system's wave out
-- volume.  This is designed to be called from an action which is triggered
-- by two gestures.
--
-- By example, the default configuration is for the mouse wheel.
-- One action will be triggered by the gestures WHEEL_DOWN *AND* WHEEL_UP
-- The script differentiates between the two and does the "right thing"
--
-- NOTE:  This requries the Alien Lua libraries.  http://alien.luaforge.net/
--
-- Change Log:		
-- July 08, 2009:
--  * Initial release
--  * Known Issue - The OSD plugin current does not remove existing text before drawing new text.
--    This causes overlapping.  To disable the OSD, comment out the call to the plugin.

-- Configure those here:
local GESTURE_VOLUME_DOWN = "WHEEL_DOWN"
local GESTURE_VOLUME_UP = "WHEEL_UP"

-- Declare references to win32 API calls for volume
-- and a few constants
-- More user-serviceable parts; the minimum and maximum volume for the script
-- to operate between, as well as the volume increment
-- NOTE:  65535 is 100% volume as specified by the win32 API
local VOL_MIN = 0
local VOL_MAX = 65535
local INCREMENT = 2000

-- END USER SERVICEABLE PARTS
require[[alien]]
local waveOutGetVolume = alien.Winmm.waveOutGetVolume
local waveOutSetVolume = alien.Winmm.waveOutSetVolume

-- Set up the API call types for the win32 calls
waveOutGetVolume:types{ ret = 'long', abi = 'stdcall', 'int', 'ref int' }
waveOutSetVolume:types{ ret = 'long', abi = 'stdcall', 'int', 'int' }

-- Get the current volume
local _, volume = waveOutGetVolume(0, 0)

-- Get the name of the gesture that triggered the script
local gesture = gesture.name()

-- For volume down
if (gesture == GESTURE_VOLUME_DOWN) then
	-- If the volume is less than the minimum
	if (volume - INCREMENT < VOL_MIN) then
		-- Set it to the minimum
		volume = VOL_MIN
	else
		-- Otherwise, decrease it by increment
		volume = volume - INCREMENT
	end
	-- Repeat for increasing the volume
elseif (gesture == GESTURE_VOLUME_UP) then
	if (volume + INCREMENT > VOL_MAX) then
		volume = VOL_MAX
	else
		volume = volume + INCREMENT
	end
end

-- Actually set he system wave out volume
waveOutSetVolume(0, volume)

-- Do a bit of math to give us a nice percentage
local volpercent = math.floor(volume / VOL_MAX * 100)
local volpercents = "Volume: " .. volpercent .. "%"

-- That we can use to call the On Screen Display plugin
local params = string.format([["%s" %d %d "%s" %d %d %d "%s" %s"]], volpercents, 500, 96, "@Arial Unicode MS", 0, 255, 0, "2", "2")
plugin.call("osd", "osd", params)
-- OSD plugin parameters:
-- Text
-- Delay (in MS)
-- Font size
-- Font name
-- RGB Red
-- RGB Green
-- RGB Blue
-- Horizontal Position (0 - Left, 1 - Center, 2 - Right)
-- Vertical Position (0 - Top, 1 - Center, 2 - Bottom)

gemisigo's cd close cd open

--!SI:Close CD:CloseCD()
--!SI:Open CD:OpenCD()

function CloseCD()
require [[alien]]
local kolbasz = alien.winmm.mciSendStringA
kolbasz:types{ ret = 'long', abi = 'stdcall', 'string', 'string', 'long', 'long'}
kolbasz("set cdaudio door closed", null, 0, 0)
end

function OpenCD()
require [[alien]]
local kolbasz = alien.winmm.mciSendStringA
kolbasz:types{ ret = 'long', abi = 'stdcall', 'string', 'string', 'long', 'long'}
kolbasz("set cdaudio door open", null, 0, 0)
end

With these you can create Lua commands using the global or re-use environment and Close CD/Open CD as a command.

Jeff's childwindow example

require[[alien]]

local GetClassName = alien.User32.GetClassNameA
GetClassName:types{ ret = 'long', abi = 'stdcall', 'long', 'pointer', 'int' }

local buf = alien.buffer(512)
GetClassName(gesture.hwnd_child(), buf, 511)

local child_class = tostring(buf);

local messagebox = alien.User32.MessageBoxA
messagebox:types{ ret = 'long', abi = 'stdcall', 'long', 'string', 'string', 'long' }

messagebox(0, "App Window: " .. string.format("0x%X", gesture.hwnd()) .. "\n\n" ..
"Child Window: " .. string.format("0x%X", gesture.hwnd_child()) .. "\n" ..
"Child Class: " .. child_class,
"Get Child Class", 0)



Edited 2 time(s). Last edit at 12/15/2009 07:28AM by Leo.
Re: Lua Scripts for upcoming StrokeIt .9.7 "enhanced" version
December 15, 2009 04:44AM
If that works on XP, neat. It was developed on 2K3 Server. I figure it's probably broken for Vista and 7 since they way that volume is handled there is different than the earlier Windows versions.
Leo
Re: Lua Scripts for upcoming StrokeIt .9.7 "enhanced" version
December 20, 2009 07:23AM
@Scott if you had the time to make it for Vista / 7 link
http://msdn.microsoft.com/en-us/library/aa964575%28VS.85%29.aspx
Author:

Your Email:


Subject:


Spam prevention:
Please, solve the mathematical question and enter the answer in the input field below. This is for blocking bots that try to post this form automatically.
Question: how much is 16 plus 25?
Message: