Open Broadcaster Software
Free, open source software for live streaming and recording
obs-hotkey.h
Go to the documentation of this file.
1 /******************************************************************************
2  Copyright (C) 2014-2015 by Ruwen Hahn <palana@stunned.de>
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 ******************************************************************************/
17 
18 #pragma once
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 typedef size_t obs_hotkey_id;
25 typedef size_t obs_hotkey_pair_id;
26 
27 #ifndef SWIG
28 #define OBS_INVALID_HOTKEY_ID (~(obs_hotkey_id)0)
29 #define OBS_INVALID_HOTKEY_PAIR_ID (~(obs_hotkey_pair_id)0)
30 #else
31 const size_t OBS_INVALID_HOTKEY_ID = (size_t)-1;
32 const size_t OBS_INVALID_HOTKEY_PAIR_ID = (size_t)-1;
33 #endif
34 
35 #define XINPUT_MOUSE_LEN 33
36 
37 enum obs_key {
38 #define OBS_HOTKEY(x) x,
39 #include "obs-hotkeys.h"
40 #undef OBS_HOTKEY
41  OBS_KEY_LAST_VALUE //not an actual key
42 };
43 typedef enum obs_key obs_key_t;
44 
46  uint32_t modifiers;
48 };
50 
51 typedef struct obs_hotkey obs_hotkey_t;
53 
60 };
62 
63 /* getter functions */
64 
72 
79 
80 /* setter functions */
81 
82 EXPORT void obs_hotkey_set_name(obs_hotkey_id id, const char *name);
83 EXPORT void obs_hotkey_set_description(obs_hotkey_id id, const char *desc);
85  const char *name1);
87  const char *desc0,
88  const char *desc1);
89 
90 #ifndef SWIG
92  const char *insert;
93  const char *del;
94  const char *home;
95  const char *end;
96  const char *page_up;
97  const char *page_down;
98  const char *num_lock;
99  const char *scroll_lock;
100  const char *caps_lock;
101  const char *backspace;
102  const char *tab;
103  const char *print;
104  const char *pause;
105  const char *left;
106  const char *right;
107  const char *up;
108  const char *down;
109  const char *shift;
110  const char *alt;
111  const char *control;
112  const char *meta; /* windows/super key */
113  const char *menu;
114  const char *space;
115  const char *numpad_num; /* For example, "Numpad %1" */
116  const char *numpad_divide;
117  const char *numpad_multiply;
118  const char *numpad_minus;
119  const char *numpad_plus;
120  const char *numpad_decimal;
121  const char *apple_keypad_num; /* For example, "%1 (Keypad)" */
122  const char *apple_keypad_divide;
124  const char *apple_keypad_minus;
125  const char *apple_keypad_plus;
126  const char *apple_keypad_decimal;
127  const char *apple_keypad_equal;
128  const char *mouse_num; /* For example, "Mouse %1" */
129  const char *escape;
130 };
131 
132 /* This function is an optional way to provide translations for specific keys
133  * that may not have translations. If the operating system can provide
134  * translations for these keys, it will use the operating system's translation
135  * over these translations. If no translations are specified, it will use
136  * the default English translations for that specific operating system. */
137 EXPORT void
139  size_t size);
140 #endif
141 
142 #define obs_hotkeys_set_translations(translations) \
143  obs_hotkeys_set_translations_s( \
144  translations, sizeof(struct obs_hotkeys_translations))
145 
146 EXPORT void
147 obs_hotkeys_set_audio_hotkeys_translations(const char *mute, const char *unmute,
148  const char *push_to_mute,
149  const char *push_to_talk);
150 
152  const char *hide);
153 
154 /* registering hotkeys (giving hotkeys a name and a function) */
155 
156 typedef void (*obs_hotkey_func)(void *data, obs_hotkey_id id,
157  obs_hotkey_t *hotkey, bool pressed);
158 
160  const char *description,
161  obs_hotkey_func func,
162  void *data);
163 
165  const char *name,
166  const char *description,
167  obs_hotkey_func func,
168  void *data);
169 
171  const char *name,
172  const char *description,
173  obs_hotkey_func func,
174  void *data);
175 
177  const char *name,
178  const char *description,
179  obs_hotkey_func func,
180  void *data);
181 
183  const char *name,
184  const char *description,
185  obs_hotkey_func func,
186  void *data);
187 
188 typedef bool (*obs_hotkey_active_func)(void *data, obs_hotkey_pair_id id,
189  obs_hotkey_t *hotkey, bool pressed);
190 
192  const char *name0, const char *description0, const char *name1,
193  const char *description1, obs_hotkey_active_func func0,
194  obs_hotkey_active_func func1, void *data0, void *data1);
195 
197  obs_encoder_t *encoder, const char *name0, const char *description0,
198  const char *name1, const char *description1,
199  obs_hotkey_active_func func0, obs_hotkey_active_func func1, void *data0,
200  void *data1);
201 
203  obs_output_t *output, const char *name0, const char *description0,
204  const char *name1, const char *description1,
205  obs_hotkey_active_func func0, obs_hotkey_active_func func1, void *data0,
206  void *data1);
207 
209  obs_service_t *service, const char *name0, const char *description0,
210  const char *name1, const char *description1,
211  obs_hotkey_active_func func0, obs_hotkey_active_func func1, void *data0,
212  void *data1);
213 
215  obs_source_t *source, const char *name0, const char *description0,
216  const char *name1, const char *description1,
217  obs_hotkey_active_func func0, obs_hotkey_active_func func1, void *data0,
218  void *data1);
219 
221 
223 
224 /* loading hotkeys (associating a hotkey with a physical key and modifiers) */
225 
227  obs_key_combination_t *combinations,
228  size_t num);
229 
231 
233  obs_data_t *hotkeys);
234 
236 
238  obs_data_t *hotkeys);
239 
241 
243  obs_data_array_t *data1);
244 
246 
248  obs_data_array_t **p_data0,
249  obs_data_array_t **p_data1);
250 
252 
254 
256 
258 
259 /* enumerating hotkeys */
260 
261 typedef bool (*obs_hotkey_enum_func)(void *data, obs_hotkey_id id,
262  obs_hotkey_t *key);
263 
265 
266 /* enumerating bindings */
267 
268 typedef bool (*obs_hotkey_binding_enum_func)(void *data, size_t idx,
269  obs_hotkey_binding_t *binding);
270 
272  void *data);
273 
274 /* hotkey event control */
275 
277 
279 
281 
282 /* hotkey callback routing (trigger callbacks through e.g. a UI thread) */
283 
284 typedef void (*obs_hotkey_callback_router_func)(void *data, obs_hotkey_id id,
285  bool pressed);
286 
287 EXPORT void
289  void *data);
290 
292 
293 /* hotkey callbacks won't be processed if callback rerouting is enabled and no
294  * router func is set */
296 
297 /* misc */
298 
299 typedef void (*obs_hotkey_atomic_update_func)(void *);
301  void *data);
302 
303 struct dstr;
304 EXPORT void obs_key_to_str(obs_key_t key, struct dstr *str);
306  struct dstr *str);
307 
310 
313 
314 static inline bool obs_key_combination_is_empty(obs_key_combination_t combo)
315 {
316  return !combo.modifiers && combo.key == OBS_KEY_NONE;
317 }
318 
319 #ifdef __cplusplus
320 }
321 #endif
obs_source
Definition: obs-internal.h:568
obs_hotkey_atomic_update_func
void(* obs_hotkey_atomic_update_func)(void *)
Definition: obs-hotkey.h:299
obs_hotkeys_save_service
EXPORT obs_data_t * obs_hotkeys_save_service(obs_service_t *service)
obs_key_t
enum obs_key obs_key_t
Definition: obs-hotkey.h:43
obs_hotkeys_translations::apple_keypad_minus
const char * apple_keypad_minus
Definition: obs-hotkey.h:124
obs_hotkeys_translations::right
const char * right
Definition: obs-hotkey.h:106
obs_hotkeys_translations::menu
const char * menu
Definition: obs-hotkey.h:113
obs_hotkey_inject_event
EXPORT void obs_hotkey_inject_event(obs_key_combination_t hotkey, bool pressed)
obs_hotkey_registerer_t
enum obs_hotkey_registerer_type obs_hotkey_registerer_t
Definition: obs-hotkey.h:61
obs_hotkeys_translations::mouse_num
const char * mouse_num
Definition: obs-hotkey.h:128
obs_hotkey_get_name
EXPORT const char * obs_hotkey_get_name(const obs_hotkey_t *key)
obs_hotkeys_translations::pause
const char * pause
Definition: obs-hotkey.h:104
obs_key
obs_key
Definition: obs-hotkey.h:37
obs_hotkey_enable_callback_rerouting
EXPORT void obs_hotkey_enable_callback_rerouting(bool enable)
obs_hotkey_pair_set_names
EXPORT void obs_hotkey_pair_set_names(obs_hotkey_pair_id id, const char *name0, const char *name1)
obs_hotkeys_translations::down
const char * down
Definition: obs-hotkey.h:108
obs_hotkeys_translations::numpad_divide
const char * numpad_divide
Definition: obs-hotkey.h:116
obs_hotkeys_translations::num_lock
const char * num_lock
Definition: obs-hotkey.h:98
obs_hotkeys_translations::apple_keypad_multiply
const char * apple_keypad_multiply
Definition: obs-hotkey.h:123
obs_key_from_name
EXPORT obs_key_t obs_key_from_name(const char *name)
obs_hotkeys_translations::meta
const char * meta
Definition: obs-hotkey.h:112
obs_hotkey_get_pair_partner_id
EXPORT obs_hotkey_id obs_hotkey_get_pair_partner_id(const obs_hotkey_t *key)
obs_hotkeys_translations::control
const char * control
Definition: obs-hotkey.h:111
obs_key_combination::modifiers
uint32_t modifiers
Definition: obs-hotkey.h:46
OBS_KEY_LAST_VALUE
@ OBS_KEY_LAST_VALUE
Definition: obs-hotkey.h:41
obs_key_from_virtual_key
EXPORT obs_key_t obs_key_from_virtual_key(int code)
obs_enum_hotkeys
EXPORT void obs_enum_hotkeys(obs_hotkey_enum_func func, void *data)
obs_hotkey_pair_save
EXPORT void obs_hotkey_pair_save(obs_hotkey_pair_id id, obs_data_array_t **p_data0, obs_data_array_t **p_data1)
obs_hotkeys_translations::shift
const char * shift
Definition: obs-hotkey.h:109
obs_hotkeys_load_encoder
EXPORT void obs_hotkeys_load_encoder(obs_encoder_t *encoder, obs_data_t *hotkeys)
obs_hotkeys_translations::numpad_multiply
const char * numpad_multiply
Definition: obs-hotkey.h:117
obs_hotkey_registerer_type
obs_hotkey_registerer_type
Definition: obs-hotkey.h:54
obs_data_t
struct obs_data obs_data_t
Definition: obs-data.h:42
obs-hotkeys.h
obs_hotkey_pair_register_source
EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_source(obs_source_t *source, const char *name0, const char *description0, const char *name1, const char *description1, obs_hotkey_active_func func0, obs_hotkey_active_func func1, void *data0, void *data1)
obs_hotkey_get_registerer_type
EXPORT obs_hotkey_registerer_t obs_hotkey_get_registerer_type(const obs_hotkey_t *key)
obs_hotkey_update_atomic
EXPORT void obs_hotkey_update_atomic(obs_hotkey_atomic_update_func func, void *data)
EXPORT
#define EXPORT
Definition: c99defs.h:37
obs_hotkey_binding_get_key_combination
EXPORT obs_key_combination_t obs_hotkey_binding_get_key_combination(obs_hotkey_binding_t *binding)
obs_hotkeys_translations::left
const char * left
Definition: obs-hotkey.h:105
obs_hotkey_pair_id
size_t obs_hotkey_pair_id
Definition: obs-hotkey.h:25
obs_hotkey_get_id
EXPORT obs_hotkey_id obs_hotkey_get_id(const obs_hotkey_t *key)
obs_hotkeys_translations::print
const char * print
Definition: obs-hotkey.h:103
obs_hotkey_pair_register_encoder
EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_encoder(obs_encoder_t *encoder, const char *name0, const char *description0, const char *name1, const char *description1, obs_hotkey_active_func func0, obs_hotkey_active_func func1, void *data0, void *data1)
obs_hotkeys_translations::page_up
const char * page_up
Definition: obs-hotkey.h:96
obs_hotkeys_translations::up
const char * up
Definition: obs-hotkey.h:107
OBS_INVALID_HOTKEY_PAIR_ID
#define OBS_INVALID_HOTKEY_PAIR_ID
Definition: obs-hotkey.h:29
obs_hotkeys_translations::page_down
const char * page_down
Definition: obs-hotkey.h:97
OBS_HOTKEY_REGISTERER_SOURCE
@ OBS_HOTKEY_REGISTERER_SOURCE
Definition: obs-hotkey.h:56
obs_hotkey_register_service
EXPORT obs_hotkey_id obs_hotkey_register_service(obs_service_t *service, const char *name, const char *description, obs_hotkey_func func, void *data)
obs_hotkeys_translations::tab
const char * tab
Definition: obs-hotkey.h:102
obs_hotkey_set_name
EXPORT void obs_hotkey_set_name(obs_hotkey_id id, const char *name)
obs_hotkeys_translations::escape
const char * escape
Definition: obs-hotkey.h:129
obs_hotkeys_translations
Definition: obs-hotkey.h:91
obs_hotkeys_translations::end
const char * end
Definition: obs-hotkey.h:95
obs_hotkeys_translations::scroll_lock
const char * scroll_lock
Definition: obs-hotkey.h:99
obs_hotkey_pair_register_frontend
EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_frontend(const char *name0, const char *description0, const char *name1, const char *description1, obs_hotkey_active_func func0, obs_hotkey_active_func func1, void *data0, void *data1)
obs_hotkey_pair_register_service
EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_service(obs_service_t *service, const char *name0, const char *description0, const char *name1, const char *description1, obs_hotkey_active_func func0, obs_hotkey_active_func func1, void *data0, void *data1)
obs_hotkeys_translations::caps_lock
const char * caps_lock
Definition: obs-hotkey.h:100
obs_hotkeys_load_output
EXPORT void obs_hotkeys_load_output(obs_output_t *output, obs_data_t *hotkeys)
obs_key_to_virtual_key
EXPORT int obs_key_to_virtual_key(obs_key_t key)
obs_hotkeys_translations::apple_keypad_equal
const char * apple_keypad_equal
Definition: obs-hotkey.h:127
obs_hotkey_active_func
bool(* obs_hotkey_active_func)(void *data, obs_hotkey_pair_id id, obs_hotkey_t *hotkey, bool pressed)
Definition: obs-hotkey.h:188
obs_hotkeys_translations::apple_keypad_decimal
const char * apple_keypad_decimal
Definition: obs-hotkey.h:126
obs_hotkeys_translations::home
const char * home
Definition: obs-hotkey.h:94
obs_key_combination_to_str
EXPORT void obs_key_combination_to_str(obs_key_combination_t key, struct dstr *str)
obs_hotkey_save
EXPORT obs_data_array_t * obs_hotkey_save(obs_hotkey_id id)
obs_hotkey
Definition: obs-internal.h:132
obs_hotkey_register_encoder
EXPORT obs_hotkey_id obs_hotkey_register_encoder(obs_encoder_t *encoder, const char *name, const char *description, obs_hotkey_func func, void *data)
obs_hotkey_pair_set_descriptions
EXPORT void obs_hotkey_pair_set_descriptions(obs_hotkey_pair_id id, const char *desc0, const char *desc1)
obs_hotkey_func
void(* obs_hotkey_func)(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey, bool pressed)
Definition: obs-hotkey.h:156
obs_hotkey_id
size_t obs_hotkey_id
Definition: obs-hotkey.h:24
obs_hotkeys_translations::alt
const char * alt
Definition: obs-hotkey.h:110
obs_hotkey_binding
Definition: obs-internal.h:175
obs_hotkeys_save_source
EXPORT obs_data_t * obs_hotkeys_save_source(obs_source_t *source)
obs_hotkeys_save_encoder
EXPORT obs_data_t * obs_hotkeys_save_encoder(obs_encoder_t *encoder)
obs_service
Definition: obs-internal.h:1118
obs_hotkeys_translations::numpad_minus
const char * numpad_minus
Definition: obs-hotkey.h:118
obs_hotkey_binding_get_hotkey_id
EXPORT obs_hotkey_id obs_hotkey_binding_get_hotkey_id(obs_hotkey_binding_t *binding)
OBS_HOTKEY_REGISTERER_OUTPUT
@ OBS_HOTKEY_REGISTERER_OUTPUT
Definition: obs-hotkey.h:57
obs_hotkeys_set_sceneitem_hotkeys_translations
EXPORT void obs_hotkeys_set_sceneitem_hotkeys_translations(const char *show, const char *hide)
obs_hotkeys_translations::backspace
const char * backspace
Definition: obs-hotkey.h:101
obs_hotkeys_set_translations_s
EXPORT void obs_hotkeys_set_translations_s(struct obs_hotkeys_translations *translations, size_t size)
obs_hotkey_binding_enum_func
bool(* obs_hotkey_binding_enum_func)(void *data, size_t idx, obs_hotkey_binding_t *binding)
Definition: obs-hotkey.h:268
obs_hotkey_unregister
EXPORT void obs_hotkey_unregister(obs_hotkey_id id)
obs_key_to_str
EXPORT void obs_key_to_str(obs_key_t key, struct dstr *str)
obs_hotkey_pair_register_output
EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_output(obs_output_t *output, const char *name0, const char *description0, const char *name1, const char *description1, obs_hotkey_active_func func0, obs_hotkey_active_func func1, void *data0, void *data1)
obs_hotkeys_translations::del
const char * del
Definition: obs-hotkey.h:93
obs_hotkey_get_description
EXPORT const char * obs_hotkey_get_description(const obs_hotkey_t *key)
obs_hotkey_register_output
EXPORT obs_hotkey_id obs_hotkey_register_output(obs_output_t *output, const char *name, const char *description, obs_hotkey_func func, void *data)
obs_hotkeys_translations::numpad_plus
const char * numpad_plus
Definition: obs-hotkey.h:119
obs_key_combination
Definition: obs-hotkey.h:45
obs_enum_hotkey_bindings
EXPORT void obs_enum_hotkey_bindings(obs_hotkey_binding_enum_func func, void *data)
obs_hotkey_set_callback_routing_func
EXPORT void obs_hotkey_set_callback_routing_func(obs_hotkey_callback_router_func func, void *data)
obs_hotkey_enable_strict_modifiers
EXPORT void obs_hotkey_enable_strict_modifiers(bool enable)
obs_hotkeys_load_service
EXPORT void obs_hotkeys_load_service(obs_service_t *service, obs_data_t *hotkeys)
obs_data_array_t
struct obs_data_array obs_data_array_t
Definition: obs-data.h:44
obs_hotkeys_translations::numpad_decimal
const char * numpad_decimal
Definition: obs-hotkey.h:120
obs_output
Definition: obs-internal.h:889
OBS_HOTKEY_REGISTERER_ENCODER
@ OBS_HOTKEY_REGISTERER_ENCODER
Definition: obs-hotkey.h:58
OBS_HOTKEY_REGISTERER_SERVICE
@ OBS_HOTKEY_REGISTERER_SERVICE
Definition: obs-hotkey.h:59
obs_hotkey_load_bindings
EXPORT void obs_hotkey_load_bindings(obs_hotkey_id id, obs_key_combination_t *combinations, size_t num)
obs_hotkey_register_frontend
EXPORT obs_hotkey_id obs_hotkey_register_frontend(const char *name, const char *description, obs_hotkey_func func, void *data)
obs_encoder
Definition: obs-internal.h:1017
obs_hotkey_enum_func
bool(* obs_hotkey_enum_func)(void *data, obs_hotkey_id id, obs_hotkey_t *key)
Definition: obs-hotkey.h:261
obs_key_combination::key
obs_key_t key
Definition: obs-hotkey.h:47
OBS_HOTKEY_REGISTERER_FRONTEND
@ OBS_HOTKEY_REGISTERER_FRONTEND
Definition: obs-hotkey.h:55
obs_hotkeys_set_audio_hotkeys_translations
EXPORT void obs_hotkeys_set_audio_hotkeys_translations(const char *mute, const char *unmute, const char *push_to_mute, const char *push_to_talk)
obs_hotkey_set_description
EXPORT void obs_hotkey_set_description(obs_hotkey_id id, const char *desc)
obs_hotkeys_translations::space
const char * space
Definition: obs-hotkey.h:114
obs_key_to_name
EXPORT const char * obs_key_to_name(obs_key_t key)
obs_hotkeys_load_source
EXPORT void obs_hotkeys_load_source(obs_source_t *source, obs_data_t *hotkeys)
obs_hotkeys_save_output
EXPORT obs_data_t * obs_hotkeys_save_output(obs_output_t *output)
obs_hotkey_binding_get_hotkey
EXPORT obs_hotkey_t * obs_hotkey_binding_get_hotkey(obs_hotkey_binding_t *binding)
dstr
Definition: dstr.h:36
obs_hotkey_register_source
EXPORT obs_hotkey_id obs_hotkey_register_source(obs_source_t *source, const char *name, const char *description, obs_hotkey_func func, void *data)
obs_hotkey_binding::key
obs_key_combination_t key
Definition: obs-internal.h:176
obs_hotkeys_translations::apple_keypad_divide
const char * apple_keypad_divide
Definition: obs-hotkey.h:122
obs_hotkey_enable_background_press
EXPORT void obs_hotkey_enable_background_press(bool enable)
obs_hotkey_load
EXPORT void obs_hotkey_load(obs_hotkey_id id, obs_data_array_t *data)
obs_hotkeys_translations::apple_keypad_plus
const char * apple_keypad_plus
Definition: obs-hotkey.h:125
obs_hotkey_callback_router_func
void(* obs_hotkey_callback_router_func)(void *data, obs_hotkey_id id, bool pressed)
Definition: obs-hotkey.h:284
obs_hotkey_trigger_routed_callback
EXPORT void obs_hotkey_trigger_routed_callback(obs_hotkey_id id, bool pressed)
obs_hotkeys_translations::insert
const char * insert
Definition: obs-hotkey.h:92
obs_hotkey_pair_unregister
EXPORT void obs_hotkey_pair_unregister(obs_hotkey_pair_id id)
OBS_INVALID_HOTKEY_ID
#define OBS_INVALID_HOTKEY_ID
Definition: obs-hotkey.h:28
obs_hotkeys_translations::apple_keypad_num
const char * apple_keypad_num
Definition: obs-hotkey.h:121
obs_hotkey_pair_load
EXPORT void obs_hotkey_pair_load(obs_hotkey_pair_id id, obs_data_array_t *data0, obs_data_array_t *data1)
obs_hotkey_get_registerer
EXPORT void * obs_hotkey_get_registerer(const obs_hotkey_t *key)
obs_hotkeys_translations::numpad_num
const char * numpad_num
Definition: obs-hotkey.h:115