tSIP: calling selected number

tSIP 0.2.07.06 adds option to run script file directly on hotkey (without using programmable button as middleman which was not too elegant) and keybd_event Lua function (WinAPI equivalent, but with 4th parameter ignored).
Script below uses this function to send Ctrl+C key combination (possibly copying selected text to clipboard from other application if assigned to global hotkey) and calls to number from clipboard.

Notes:

local function testflag(set, flag)
  return set % (2*flag) >= flag
end

local winapi = require("tsip_winapi")

-- wait until all keys are up
local allUp
for i = 1, 500 do
	allUp = true
	for j = 1, 255 do
		local keyState = winapi.GetAsyncKeyState(j)
		if testflag(keyState, 32768) then
			allUp = false
			break
		end
	end
	if allUp == true then
		break;
	end
	Sleep(20)
end

if allUp == false then
	print("Timed-out waiting for key release, can't send key combination!\n")
	return
end

local KEYEVENTF_KEYDOWN = 0x0000
local KEYEVENTF_EXTENDEDKEY = 0x0001
local KEYEVENTF_KEYUP = 0x0002

-- simulating Ctrl+C keypress
winapi.keybd_event(0xA2, 0, KEYEVENTF_KEYDOWN)	-- 0xA2 = Left Ctrl
winapi.keybd_event(0x43, 0, KEYEVENTF_KEYDOWN)	-- 0x43 = 'C' key
Sleep(20)
winapi.keybd_event(0x43, 0, KEYEVENTF_KEYUP)
winapi.keybd_event(0xA2, 0, KEYEVENTF_KEYUP)

Sleep(50)
local clipboardText = GetClipboardText()
print(string.format("Clipboard text = [%s]\n", clipboardText))

-- this removes all characters outside of defined set
target = clipboardText:gsub("[^+0123456789*#ABCD]", "")

if target ~= "" then
	Call(target)
end

Back to howto list.