[Interface] Hotkeys
Posted: 26 Jun 2013 13:16
It is possible to define custom hotkeys and actions using the hotkeys Lua interface script.
Original hotkeys demo interface script:
An abstract:
hotkeys.lua - an example of usage:
x = Rewind = Play from the start
t = OSD Codec Information and Name = Show Codec Information and Name on the screen in a playing videoInstallation (VLC-2.0.x, Windows):
1.) Find "hotkeys.luac" file in VLC in your computer (lua\intf\hotkeys.luac) and replace it with your custom script "hotkeys.lua".
2.) Tools > Preferences > ( Show settings = All ) > Interface \ Main interfaces: [luaintf] = write "luaintf" (without quotes) in the text input field
Tools > Preferences > ( Show settings = All ) > Interface \ Main interfaces \ Lua: Lua interface [hotkeys]
3.) Save changes, restart VLC, enjoy
Or you can use CLI (batch file or desktop shortcut icon) instead of preferences:
Please share your ideas and enhancements of the script here.
Original hotkeys demo interface script:
Code: Select all
--[==========================================================================[
hotkeys.lua: hotkey handling for VLC
--[==========================================================================[
Copyright (C) 2007 the VideoLAN team
$Id$
Authors: Antoine Cellerier <dionoea at videolan dot org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
--]==========================================================================]
--[==========================================================================[
This is meant to replace modules/control/hotkeys.c
(which will require some changes in the VLC core hotkeys stuff)
--]==========================================================================]
require("common")
--common.table_print(vlc,"vlc.\t")
bindings = {
["Ctrl-q"] = "quit",
["Space"] = "play-pause",
[113] --[[q]] = "quit",
[119] --[[w]] = "demo",
[120] --[[x]] = "demo2",
}
function quit()
print("Bye-bye!")
vlc.misc.quit()
end
function demo()
vlc.osd.icon("speaker")
end
function demo2()
if not channel1 then
channel1 = vlc.osd.channel_register()
channel2 = vlc.osd.channel_register()
end
vlc.osd.message("Hey!",channel1)
vlc.osd.slider( 10, "horizontal", channel2 )
end
function action(func,delta)
return { func = func, delta = delta or 0, last = 0, times = 0 }
end
actions = {
["quit"] = action(quit),
["play-pause"] = action(play_pause),
["demo"] = action(demo),
["demo2"] = action(demo2),
}
action = nil
queue = {}
function action_trigger( action )
print("action_trigger:",tostring(action))
local a = actions[action]
if a then
local ok, msg = pcall( a.func )
if not ok then
vlc.msg.err("Error while executing action `".. tostring(action) .."': "..msg)
end
else
vlc.msg.err("Key `"..key.."' points to unknown action `"..bindings[key].."'.")
end
end
function key_press( var, old, key, data )
print("key_press:",tostring(key))
if bindings[key] then
action_trigger(bindings[key])
else
vlc.msg.err("Key `"..key.."' isn't bound to any action.")
end
end
vlc.var.add_callback( vlc.object.libvlc(), "key-pressed", key_press )
--vlc.var.add_callback( vlc.object.libvlc(), "action-triggered", action_trigger )
while not vlc.misc.lock_and_wait() do
end
-- Clean up
vlc.var.del_callback( vlc.object.libvlc(), "key-pressed", key_press )
--vlc.var.del_callback( vlc.object.libvlc(), "action-triggered", action_trigger )
Code: Select all
function key_press( var, old, key, data )
if key==120 then
-- "x" key was pressed, do something
end
end
vlc.var.add_callback( vlc.object.libvlc(), "key-pressed", key_press )
x = Rewind = Play from the start
t = OSD Codec Information and Name = Show Codec Information and Name on the screen in a playing video
Code: Select all
mtitle = "[hotkeys]"
function Log(m)
vlc.msg.info(mtitle.." "..m)
end
-- Play from the start
function Rewind(m)
Log(m)
local input=vlc.object.input()
if input then vlc.var.set(input, "time", 0) end
end
-- Show Codec Information and Name on the screen in a playing video
t=10 -- seconds
t0=-t
function OSD_Codec_Info(m)
Log(m)
t1=os.clock()
if t1>(t0+t) then
t0=t1
local input_item = vlc.input.item()
if input_item then
local info_table = input_item:info()
local info_output = "Codec Information:\n"
for k0,v0 in pairs(info_table) do
info_output = info_output .. ">> " .. k0 .. ": "
for _,v1 in pairs(v0) do
info_output = info_output .. v1 .. ", "
end
info_output = string.gsub(info_output, "^(.*), $", "%1;")
info_output = info_output .. "\n"
end
channel1 = vlc.osd.channel_register()
channel2 = vlc.osd.channel_register()
vlc.osd.message(info_output,channel1,"top-left",t*1000000)
vlc.osd.message(input_item:name(),channel2,"bottom",t*1000000)
end
else
t0=-t
vlc.osd.message("",channel1)
vlc.osd.message("",channel2)
end
end
function key_press( var, old, key, data )
Log("Key code: " .. key)
if key==116 then OSD_Codec_Info("t = OSD Codec Information and Name") end
if key==120 then Rewind("x = Rewind") end
end
vlc.var.add_callback( vlc.object.libvlc(), "key-pressed", key_press )
1.) Find "hotkeys.luac" file in VLC in your computer (lua\intf\hotkeys.luac) and replace it with your custom script "hotkeys.lua".
2.) Tools > Preferences > ( Show settings = All ) > Interface \ Main interfaces: [luaintf] = write "luaintf" (without quotes) in the text input field
Tools > Preferences > ( Show settings = All ) > Interface \ Main interfaces \ Lua: Lua interface [hotkeys]
3.) Save changes, restart VLC, enjoy
Or you can use CLI (batch file or desktop shortcut icon) instead of preferences:
Code: Select all
vlc.exe --extraintf=luaintf --lua-intf=hotkeys