Open Broadcaster Software
Free, open source software for live streaming and recording
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 #define OBS_INVALID_HOTKEY_ID (~(obs_hotkey_id)0)
26 typedef size_t obs_hotkey_pair_id;
27 #define OBS_INVALID_HOTKEY_PAIR_ID (~(obs_hotkey_pair_id)0)
28 
29 enum obs_key {
30 #define OBS_HOTKEY(x) x,
31 #include "obs-hotkeys.h"
32 #undef OBS_HOTKEY
33  OBS_KEY_LAST_VALUE //not an actual key
34 };
35 typedef enum obs_key obs_key_t;
36 
39  obs_key_t key;
40 };
42 
43 typedef struct obs_hotkey obs_hotkey_t;
45 
52 };
54 
55 EXPORT obs_hotkey_id obs_hotkey_get_id(const obs_hotkey_t *key);
56 EXPORT const char *obs_hotkey_get_name(const obs_hotkey_t *key);
58 EXPORT obs_hotkey_registerer_t obs_hotkey_get_registerer_type(
59  const obs_hotkey_t *key);
62 
63 
65  obs_hotkey_binding_t *binding);
67  obs_hotkey_binding_t *binding);
69  obs_hotkey_binding_t *binding);
70 
72  const char *insert;
73  const char *del;
74  const char *home;
75  const char *end;
76  const char *page_up;
77  const char *page_down;
78  const char *num_lock;
79  const char *scroll_lock;
80  const char *caps_lock;
81  const char *backspace;
82  const char *tab;
83  const char *print;
84  const char *pause;
85  const char *left;
86  const char *right;
87  const char *up;
88  const char *down;
89  const char *shift;
90  const char *alt;
91  const char *control;
92  const char *meta; /* windows/super key */
93  const char *menu;
94  const char *space;
95  const char *numpad_num; /* For example, "Numpad %1" */
96  const char *numpad_divide;
97  const char *numpad_multiply;
98  const char *numpad_minus;
99  const char *numpad_plus;
100  const char *numpad_decimal;
101  const char *apple_keypad_num; /* For example, "%1 (Keypad)" */
102  const char *apple_keypad_divide;
104  const char *apple_keypad_minus;
105  const char *apple_keypad_plus;
106  const char *apple_keypad_decimal;
107  const char *apple_keypad_equal;
108  const char *mouse_num; /* For example, "Mouse %1" */
109 };
110 
111 /* This function is an optional way to provide translations for specific keys
112  * that may not have translations. If the operating system can provide
113  * translations for these keys, it will use the operating system's translation
114  * over these translations. If no translations are specified, it will use
115  * the default english translations for that specific operating system. */
117  struct obs_hotkeys_translations *translations, size_t size);
118 
119 #define obs_hotkeys_set_translations(translations) \
120  obs_hotkeys_set_translations_s(translations, \
121  sizeof(struct obs_hotkeys_translations))
122 
124  const char *mute, const char *unmute,
125  const char *push_to_mute, const char *push_to_talk);
126 
128  const char *show, const char *hide);
129 
130 /* registering hotkeys (giving hotkeys a name and a function) */
131 
132 typedef void (*obs_hotkey_func)(void *data,
133  obs_hotkey_id id, obs_hotkey_t *hotkey, bool pressed);
134 
135 EXPORT obs_hotkey_id obs_hotkey_register_frontend(const char *name,
136  const char *description, obs_hotkey_func func, void *data);
137 
138 EXPORT obs_hotkey_id obs_hotkey_register_encoder(obs_encoder_t *encoder,
139  const char *name, const char *description,
140  obs_hotkey_func func, void *data);
141 
142 EXPORT obs_hotkey_id obs_hotkey_register_output(obs_output_t *output,
143  const char *name, const char *description,
144  obs_hotkey_func func, void *data);
145 
146 EXPORT obs_hotkey_id obs_hotkey_register_service(obs_service_t *service,
147  const char *name, const char *description,
148  obs_hotkey_func func, void *data);
149 
150 EXPORT obs_hotkey_id obs_hotkey_register_source(obs_source_t *source,
151  const char *name, const char *description,
152  obs_hotkey_func func, void *data);
153 
154 typedef bool (*obs_hotkey_active_func)(void *data,
155  obs_hotkey_pair_id id, obs_hotkey_t *hotkey, bool pressed);
156 
157 EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_frontend(
158  const char *name0, const char *description0,
159  const char *name1, const char *description1,
161  void *data0, void *data1);
162 
163 EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_encoder(
164  obs_encoder_t *encoder,
165  const char *name0, const char *description0,
166  const char *name1, const char *description1,
168  void *data0, void *data1);
169 
170 EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_output(
171  obs_output_t *output,
172  const char *name0, const char *description0,
173  const char *name1, const char *description1,
175  void *data0, void *data1);
176 
177 EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_service(
178  obs_service_t *service,
179  const char *name0, const char *description0,
180  const char *name1, const char *description1,
182  void *data0, void *data1);
183 
184 EXPORT obs_hotkey_pair_id obs_hotkey_pair_register_source(
185  obs_source_t *source,
186  const char *name0, const char *description0,
187  const char *name1, const char *description1,
189  void *data0, void *data1);
190 
191 EXPORT void obs_hotkey_unregister(obs_hotkey_id id);
192 
193 EXPORT void obs_hotkey_pair_unregister(obs_hotkey_pair_id id);
194 
195 /* loading hotkeys (associating a hotkey with a physical key and modifiers) */
196 
197 EXPORT void obs_hotkey_load_bindings(obs_hotkey_id id,
198  obs_key_combination_t *combinations, size_t num);
199 
200 EXPORT void obs_hotkey_load(obs_hotkey_id id, obs_data_array_t *data);
201 
203  obs_data_t *hotkeys);
204 
205 EXPORT void obs_hotkeys_load_output(obs_output_t *output, obs_data_t *hotkeys);
206 
208  obs_data_t *hotkeys);
209 
210 EXPORT void obs_hotkeys_load_source(obs_source_t *source, obs_data_t *hotkeys);
211 
212 EXPORT void obs_hotkey_pair_load(obs_hotkey_pair_id id, obs_data_array_t *data0,
213  obs_data_array_t *data1);
214 
215 
216 EXPORT obs_data_array_t *obs_hotkey_save(obs_hotkey_id id);
217 
219 
221 
223 
225 
226 /* enumerating hotkeys */
227 
228 typedef bool (*obs_hotkey_enum_func)(void *data,
229  obs_hotkey_id id, obs_hotkey_t *key);
230 
231 EXPORT void obs_enum_hotkeys(obs_hotkey_enum_func func, void *data);
232 
233 /* enumerating bindings */
234 
235 typedef bool (*obs_hotkey_binding_enum_func)(void *data,
236  size_t idx, obs_hotkey_binding_t* binding);
237 
239  void *data);
240 
241 /* hotkey event control */
242 
243 EXPORT void obs_hotkey_inject_event(obs_key_combination_t hotkey, bool pressed);
244 
246 
248 
249 /* hotkey callback routing (trigger callbacks through e.g. a UI thread) */
250 
251 typedef void (*obs_hotkey_callback_router_func)(void *data,
252  obs_hotkey_id id, bool pressed);
253 
255  func, void *data);
256 
257 EXPORT void obs_hotkey_trigger_routed_callback(obs_hotkey_id id, bool pressed);
258 
259 /* hotkey callbacks won't be processed if callback rerouting is enabled and no
260  * router func is set */
262 
263 /* misc */
264 
265 typedef void (*obs_hotkey_atomic_update_func)(void *);
267  void *data);
268 
269 struct dstr;
270 EXPORT void obs_key_to_str(obs_key_t key, struct dstr *str);
272  struct dstr *str);
273 
274 EXPORT obs_key_t obs_key_from_virtual_key(int code);
275 EXPORT int obs_key_to_virtual_key(obs_key_t key);
276 
277 EXPORT const char *obs_key_to_name(obs_key_t key);
278 EXPORT obs_key_t obs_key_from_name(const char *name);
279 
281 {
282  return !combo.modifiers && combo.key == OBS_KEY_NONE;
283 }
284 
285 #ifdef __cplusplus
286 }
287 #endif
Definition: obs-hotkey.h:511
EXPORT void * obs_hotkey_get_registerer(const obs_hotkey_t *key)
EXPORT void obs_key_to_str(obs_key_t key, struct dstr *str)
EXPORT void obs_hotkey_load(obs_hotkey_id id, obs_data_array_t *data)
EXPORT void obs_hotkey_trigger_routed_callback(obs_hotkey_id id, bool pressed)
bool obs_key_combination_is_empty(obs_key_combination_t combo)
Definition: obs-hotkey.h:280
EXPORT void obs_hotkey_pair_load(obs_hotkey_pair_id id, obs_data_array_t *data0, obs_data_array_t *data1)
const char * del
Definition: obs-hotkey.h:73
size_t obs_hotkey_id
Definition: obs-hotkey.h:24
const char * num_lock
Definition: obs-hotkey.h:78
EXPORT void obs_enum_hotkey_bindings(obs_hotkey_binding_enum_func func, void *data)
EXPORT void obs_enum_hotkeys(obs_hotkey_enum_func func, void *data)
const char * up
Definition: obs-hotkey.h:87
const char * down
Definition: obs-hotkey.h:88
const char * control
Definition: obs-hotkey.h:91
EXPORT obs_data_array_t * obs_hotkey_save(obs_hotkey_id id)
const char * apple_keypad_multiply
Definition: obs-hotkey.h:103
Definition: obs-internal.h:797
unsigned uint32_t
Definition: vc_stdint.h:31
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)
void(* obs_hotkey_func)(void *data, obs_hotkey_id id, obs_hotkey_t *hotkey, bool pressed)
Definition: obs-hotkey.h:132
EXPORT obs_data_t * obs_hotkeys_save_service(obs_service_t *service)
Definition: obs-internal.h:519
const char * numpad_num
Definition: obs-hotkey.h:95
EXPORT void obs_hotkeys_load_source(obs_source_t *source, obs_data_t *hotkeys)
const char * scroll_lock
Definition: obs-hotkey.h:79
EXPORT void obs_hotkeys_load_output(obs_output_t *output, obs_data_t *hotkeys)
const char * numpad_multiply
Definition: obs-hotkey.h:97
EXPORT obs_hotkey_id obs_hotkey_register_encoder(obs_encoder_t *encoder, const char *name, const char *description, obs_hotkey_func func, void *data)
Definition: obs-hotkey.h:48
EXPORT obs_hotkey_id obs_hotkey_register_output(obs_output_t *output, const char *name, const char *description, obs_hotkey_func func, void *data)
Definition: obs-hotkey.h:37
EXPORT void obs_hotkeys_set_translations_s(struct obs_hotkeys_translations *translations, size_t size)
const char * print
Definition: obs-hotkey.h:83
const char * page_down
Definition: obs-hotkey.h:77
struct obs_data obs_data_t
Definition: obs-data.h:42
EXPORT void obs_hotkey_set_callback_routing_func(obs_hotkey_callback_router_func func, void *data)
void(* obs_hotkey_atomic_update_func)(void *)
Definition: obs-hotkey.h:265
EXPORT void obs_hotkey_enable_strict_modifiers(bool enable)
const char * mouse_num
Definition: obs-hotkey.h:108
const char * alt
Definition: obs-hotkey.h:90
Definition: obs-internal.h:167
const char * numpad_plus
Definition: obs-hotkey.h:99
const char * end
Definition: obs-hotkey.h:75
Definition: obs-hotkey.h:71
bool(* obs_hotkey_enum_func)(void *data, obs_hotkey_id id, obs_hotkey_t *key)
Definition: obs-hotkey.h:228
obs_hotkey_registerer_type
Definition: obs-hotkey.h:46
const char * apple_keypad_num
Definition: obs-hotkey.h:101
#define EXPORT
Definition: c99defs.h:49
const char * apple_keypad_decimal
Definition: obs-hotkey.h:106
EXPORT obs_hotkey_id obs_hotkey_register_frontend(const char *name, const char *description, obs_hotkey_func func, void *data)
obs_key
Definition: obs-hotkey.h:29
const char * apple_keypad_equal
Definition: obs-hotkey.h:107
obs_key_t key
Definition: obs-hotkey.h:39
const char * page_up
Definition: obs-hotkey.h:76
EXPORT void obs_hotkeys_set_audio_hotkeys_translations(const char *mute, const char *unmute, const char *push_to_mute, const char *push_to_talk)
Definition: obs-internal.h:911
enum obs_key obs_key_t
Definition: obs-hotkey.h:35
const char * right
Definition: obs-hotkey.h:86
const char * tab
Definition: obs-hotkey.h:82
EXPORT obs_data_t * obs_hotkeys_save_output(obs_output_t *output)
const char * menu
Definition: obs-hotkey.h:93
EXPORT obs_hotkey_registerer_t obs_hotkey_get_registerer_type(const obs_hotkey_t *key)
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_key_combination_t key
Definition: obs-internal.h:168
EXPORT obs_key_t obs_key_from_virtual_key(int code)
EXPORT void obs_hotkeys_load_encoder(obs_encoder_t *encoder, obs_data_t *hotkeys)
EXPORT obs_hotkey_id obs_hotkey_get_pair_partner_id(const obs_hotkey_t *key)
void(* obs_hotkey_callback_router_func)(void *data, obs_hotkey_id id, bool pressed)
Definition: obs-hotkey.h:251
const char * numpad_decimal
Definition: obs-hotkey.h:100
EXPORT const char * obs_hotkey_get_name(const obs_hotkey_t *key)
EXPORT void obs_hotkey_enable_background_press(bool enable)
const char * apple_keypad_minus
Definition: obs-hotkey.h:104
const char * backspace
Definition: obs-hotkey.h:81
Definition: obs-hotkey.h:50
size_t obs_hotkey_pair_id
Definition: obs-hotkey.h:26
const char * shift
Definition: obs-hotkey.h:89
bool(* obs_hotkey_binding_enum_func)(void *data, size_t idx, obs_hotkey_binding_t *binding)
Definition: obs-hotkey.h:235
EXPORT int obs_key_to_virtual_key(obs_key_t key)
Definition: dstr.h:36
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)
const char * meta
Definition: obs-hotkey.h:92
EXPORT obs_hotkey_id obs_hotkey_binding_get_hotkey_id(obs_hotkey_binding_t *binding)
EXPORT const char * obs_key_to_name(obs_key_t key)
Definition: obs-hotkey.h:49
const char * left
Definition: obs-hotkey.h:85
EXPORT void obs_hotkeys_load_service(obs_service_t *service, obs_data_t *hotkeys)
EXPORT void obs_hotkeys_set_sceneitem_hotkeys_translations(const char *show, const char *hide)
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)
Definition: obs-hotkey.h:47
EXPORT void obs_hotkey_pair_unregister(obs_hotkey_pair_id id)
uint32_t modifiers
Definition: obs-hotkey.h:38
EXPORT obs_key_t obs_key_from_name(const char *name)
const char * numpad_minus
Definition: obs-hotkey.h:98
EXPORT void obs_hotkey_unregister(obs_hotkey_id id)
struct obs_data_array obs_data_array_t
Definition: obs-data.h:44
EXPORT obs_key_combination_t obs_hotkey_binding_get_key_combination(obs_hotkey_binding_t *binding)
Definition: obs-internal.h:996
enum obs_hotkey_registerer_type obs_hotkey_registerer_t
Definition: obs-hotkey.h:53
const char * space
Definition: obs-hotkey.h:94
const char * numpad_divide
Definition: obs-hotkey.h:96
const char * caps_lock
Definition: obs-hotkey.h:80
EXPORT void obs_hotkey_load_bindings(obs_hotkey_id id, obs_key_combination_t *combinations, size_t num)
const char * apple_keypad_divide
Definition: obs-hotkey.h:102
EXPORT obs_hotkey_id obs_hotkey_get_id(const obs_hotkey_t *key)
EXPORT obs_data_t * obs_hotkeys_save_encoder(obs_encoder_t *encoder)
EXPORT obs_hotkey_id obs_hotkey_register_service(obs_service_t *service, const char *name, const char *description, obs_hotkey_func func, void *data)
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)
Definition: obs-internal.h:124
const char * pause
Definition: obs-hotkey.h:84
EXPORT obs_hotkey_t * obs_hotkey_binding_get_hotkey(obs_hotkey_binding_t *binding)
EXPORT void obs_hotkey_update_atomic(obs_hotkey_atomic_update_func func, void *data)
#define bool
Definition: vc_stdbool.h:5
Definition: obs-hotkey.h:51
EXPORT void obs_hotkey_enable_callback_rerouting(bool enable)
const char * apple_keypad_plus
Definition: obs-hotkey.h:105
const char * insert
Definition: obs-hotkey.h:72
EXPORT const char * obs_hotkey_get_description(const obs_hotkey_t *key)
bool(* obs_hotkey_active_func)(void *data, obs_hotkey_pair_id id, obs_hotkey_t *hotkey, bool pressed)
Definition: obs-hotkey.h:154
EXPORT obs_data_t * obs_hotkeys_save_source(obs_source_t *source)
EXPORT void obs_key_combination_to_str(obs_key_combination_t key, struct dstr *str)
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)
EXPORT void obs_hotkey_inject_event(obs_key_combination_t hotkey, bool pressed)
const char * home
Definition: obs-hotkey.h:74