]> git.sesse.net Git - vlc/blob - share/lua/intf/hotkeys.lua
lua: fix hotkeys demo file.
[vlc] / share / lua / intf / hotkeys.lua
1 --[==========================================================================[
2  hotkeys.lua: hotkey handling for VLC
3 --[==========================================================================[
4  Copyright (C) 2007 the VideoLAN team
5  $Id$
6
7  Authors: Antoine Cellerier <dionoea at videolan dot org>
8
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 --]==========================================================================]
23
24 --[==========================================================================[
25     This is meant to replace modules/control/hotkeys.c
26     (which will require some changes in the VLC core hotkeys stuff)
27 --]==========================================================================]
28
29 require("common")
30 --common.table_print(vlc,"vlc.\t")
31
32 bindings = {
33     ["Ctrl-q"] = "quit",
34     ["Space"] = "play-pause",
35     [113] --[[q]] = "quit",
36     [119] --[[w]] = "demo",
37     [120] --[[x]] = "demo2",
38     }
39
40 function quit()
41     print("Bye-bye!")
42     vlc.misc.quit()
43 end
44
45 function demo()
46     vlc.osd.icon("speaker")
47 end
48
49 function demo2()
50     if not channel1 then
51         channel1 = vlc.osd.channel_register()
52         channel2 = vlc.osd.channel_register()
53     end
54     vlc.osd.message("Hey!",channel1)
55     vlc.osd.slider( 10, "horizontal", channel2 )
56 end
57
58 function action(func,delta)
59     return { func = func, delta = delta or 0, last = 0, times = 0 }
60 end
61
62 actions = {
63     ["quit"] = action(quit),
64     ["play-pause"] = action(play_pause),
65     ["demo"] = action(demo),
66     ["demo2"] = action(demo2),
67     }
68
69 action = nil
70
71 queue = {}
72
73 function action_trigger( action )
74     print("action_trigger:",tostring(action))
75     local a = actions[action]
76     if a then
77         local ok, msg = pcall( a.func )
78         if not ok then
79             vlc.msg.err("Error while executing action `".. tostring(action) .."': "..msg)
80         end
81     else
82         vlc.msg.err("Key `"..key.."' points to unknown action `"..bindings[key].."'.")
83     end
84 end
85
86 function key_press( var, old, key, data )
87     print("key_press:",tostring(key))
88     if bindings[key] then
89         action_trigger(bindings[key])
90     else
91         vlc.msg.err("Key `"..key.."' isn't bound to any action.")
92     end
93 end
94
95 vlc.var.add_callback( vlc.object.libvlc(), "key-pressed", key_press )
96 --vlc.var.add_callback( vlc.object.libvlc(), "action-triggered", action_trigger )
97
98 while not vlc.misc.lock_and_wait() do
99 end
100
101 -- Clean up
102 vlc.var.del_callback( vlc.object.libvlc(), "key-pressed", key_press )
103 --vlc.var.del_callback( vlc.object.libvlc(), "action-triggered", action_trigger )