in case your keyboard does not have media control keys, this will send commands to iTunes. left control + right = next song left control + left = previous song left control + up = volume up left control + down = volume down left control + space = pause/play or start iTunes... it does not start playing automatically yet i may try again later hold control after a direction = repeat i may try to get it working better or clean up the code, anyway it covers the basics for now. set start trigger to {<lcontrolkey>} Code: begin Keyboard.Suppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") // keep this lower than repeat_search_pause Variable.Set("milliseconds_to_wait", "10") // ms to hold the key Variable.Set("hold_pause", "1") // detection interval Variable.Set("repeat_search_pause", "50") // how long until it repeats command if control held Variable.Set("repeat_key_pause", "1500") // time to wait after starting iTunes and playing first song Variable.Set("start_wait", "2000") if Variable.Does not exist("time") begin Macro.Start stopwatch("last_pressed") end if Window.Is running("iTunes", "yes") begin Variable.Set("running", "yes") end Keyboard.Get last key press("key") if Variable.Is equal to("key", "left") and Variable.Exists("running") begin Window.Send hold keys("iTunes", "yes", "0", "{<rcontrolkey>}") Window.Send hold keys("iTunes", "yes", "0", "{<left>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<left>}") Window.Send release keys("iTunes", "yes", "0", "{<rcontrolkey>}") Keyboard.Unsuppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") Macro.Pause("{repeat_key_pause}") end if Variable.Is equal to("key", "right") and Variable.Exists("running") begin Window.Send hold keys("iTunes", "yes", "0", "{<rcontrolkey>}") Window.Send hold keys("iTunes", "yes", "0", "{<right>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<right>}") Window.Send release keys("iTunes", "yes", "0", "{<rcontrolkey>}") Keyboard.Unsuppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") Macro.Pause("{repeat_key_pause}") end if Variable.Is equal to("key", "up") and Variable.Exists("running") begin Window.Send hold keys("iTunes", "yes", "0", "{<rcontrolkey>}") Window.Send hold keys("iTunes", "yes", "0", "{<up>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<up>}") Window.Send release keys("iTunes", "yes", "0", "{<rcontrolkey>}") Keyboard.Unsuppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") Macro.Pause("{repeat_key_pause}") end if Variable.Is equal to("key", "down") and Variable.Exists("running") begin Window.Send hold keys("iTunes", "yes", "0", "{<rcontrolkey>}") Window.Send hold keys("iTunes", "yes", "0", "{<down>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<down>}") Window.Send release keys("iTunes", "yes", "0", "{<rcontrolkey>}") Keyboard.Unsuppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") Macro.Pause("{repeat_key_pause}") end if Variable.Is equal to("key", "space") begin Keyboard.Suppress keys("{<lcontrolkey>}") if Variable.Does not exist("running") begin System.Launch application ("iTunes", "no") Keyboard.Unsuppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") Macro.Pause("{start_wait}") Window.Minimize("iTunes", "yes") Macro.Pause("400") Window.Send hold keys("iTunes", "yes", "0", "{<rcontrolkey>}") Window.Send hold keys("iTunes", "yes", "0", "{<right>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<right>}") Window.Send release keys("iTunes", "yes", "0", "{<rcontrolkey>}") Macro.Pause("30") Window.Send hold keys("iTunes", "yes", "0", "{<space>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<space>}") Macro.Pause("{hold_pause}") Window.Send hold keys("iTunes", "yes", "0", "{<space>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<space>}") Macro.Pause("{hold_pause}") end Window.Send hold keys("iTunes", "yes", "0", "{<space>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<space>}") Keyboard.Unsuppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") Macro.Pause("{repeat_key_pause}") Keyboard.Unsuppress keys("{<lcontrolkey>}") end if Keyboard.Key is held down("{<lcontrolkey>}") begin Macro.Restart stopwatch("last_pressed") end Macro.Read stopwatch("last_pressed", "time") if Variable.Is equal to("key", "{<lcontrolkey>}") or Variable.Is less than (Math)("time", "{milliseconds_to_wait}") begin Function.Execute("restart") end Function.Execute("stop") end
function("restart") begin Macro.Pause("{repeat_search_pause}") Macro.Restart("no") end function
function("stop") begin Keyboard.Unsuppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") Macro.Abort() end function
in case your keyboard does not have media control keys, this will send commands to iTunes.
left control + right = next song left control + left = previous song left control + up = volume up left control + down = volume down left control + space = pause/play or start iTunes... it does not start playing automatically yet i may try again later hold control after a direction = repeat
i may try to get it working better or clean up the code, anyway it covers the basics for now. set start trigger to {<lcontrolkey>}[code] begin Keyboard.Suppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") // keep this lower than repeat_search_pause Variable.Set("milliseconds_to_wait", "10") // ms to hold the key Variable.Set("hold_pause", "1") // detection interval Variable.Set("repeat_search_pause", "50") // how long until it repeats command if control held Variable.Set("repeat_key_pause", "1500") // time to wait after starting iTunes and playing first song Variable.Set("start_wait", "2000") if Variable.Does not exist("time") begin Macro.Start stopwatch("last_pressed") end if Window.Is running("iTunes", "yes") begin Variable.Set("running", "yes") end Keyboard.Get last key press("key") if Variable.Is equal to("key", "left") and Variable.Exists("running") begin Window.Send hold keys("iTunes", "yes", "0", "{<rcontrolkey>}") Window.Send hold keys("iTunes", "yes", "0", "{<left>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<left>}") Window.Send release keys("iTunes", "yes", "0", "{<rcontrolkey>}") Keyboard.Unsuppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") Macro.Pause("{repeat_key_pause}") end if Variable.Is equal to("key", "right") and Variable.Exists("running") begin Window.Send hold keys("iTunes", "yes", "0", "{<rcontrolkey>}") Window.Send hold keys("iTunes", "yes", "0", "{<right>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<right>}") Window.Send release keys("iTunes", "yes", "0", "{<rcontrolkey>}") Keyboard.Unsuppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") Macro.Pause("{repeat_key_pause}") end if Variable.Is equal to("key", "up") and Variable.Exists("running") begin Window.Send hold keys("iTunes", "yes", "0", "{<rcontrolkey>}") Window.Send hold keys("iTunes", "yes", "0", "{<up>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<up>}") Window.Send release keys("iTunes", "yes", "0", "{<rcontrolkey>}") Keyboard.Unsuppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") Macro.Pause("{repeat_key_pause}") end if Variable.Is equal to("key", "down") and Variable.Exists("running") begin Window.Send hold keys("iTunes", "yes", "0", "{<rcontrolkey>}") Window.Send hold keys("iTunes", "yes", "0", "{<down>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<down>}") Window.Send release keys("iTunes", "yes", "0", "{<rcontrolkey>}") Keyboard.Unsuppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") Macro.Pause("{repeat_key_pause}") end if Variable.Is equal to("key", "space") begin Keyboard.Suppress keys("{<lcontrolkey>}") if Variable.Does not exist("running") begin System.Launch application ("iTunes", "no") Keyboard.Unsuppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") Macro.Pause("{start_wait}") Window.Minimize("iTunes", "yes") Macro.Pause("400") Window.Send hold keys("iTunes", "yes", "0", "{<rcontrolkey>}") Window.Send hold keys("iTunes", "yes", "0", "{<right>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<right>}") Window.Send release keys("iTunes", "yes", "0", "{<rcontrolkey>}") Macro.Pause("30") Window.Send hold keys("iTunes", "yes", "0", "{<space>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<space>}") Macro.Pause("{hold_pause}") Window.Send hold keys("iTunes", "yes", "0", "{<space>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<space>}") Macro.Pause("{hold_pause}") end Window.Send hold keys("iTunes", "yes", "0", "{<space>}") Macro.Pause("{hold_pause}") Window.Send release keys("iTunes", "yes", "0", "{<space>}") Keyboard.Unsuppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") Macro.Pause("{repeat_key_pause}") Keyboard.Unsuppress keys("{<lcontrolkey>}") end if Keyboard.Key is held down("{<lcontrolkey>}") begin Macro.Restart stopwatch("last_pressed") end Macro.Read stopwatch("last_pressed", "time") if Variable.Is equal to("key", "{<lcontrolkey>}") or Variable.Is less than (Math)("time", "{milliseconds_to_wait}") begin Function.Execute("restart") end Function.Execute("stop") end
function("restart") begin Macro.Pause("{repeat_search_pause}") Macro.Restart("no") end function
function("stop") begin Keyboard.Unsuppress keys("{<left>}{<right>}{<up>}{<down>}{<space>}") Macro.Abort() end function [/code]
|