1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Global hotkey management.
use super::Client;
use teamtalk_sys as ffi;
impl Client {
/// Registers a global hotkey.
///
/// Returns `false` when the client was created with `Client::new()` instead of
/// `Client::with_hwnd()`.
pub fn register_hotkey(&self, id: i32, vk_codes: &[i32]) -> bool {
if !self.is_hwnd_client() {
return false;
}
unsafe {
ffi::api().TT_HotKey_Register(self.ptr.0, id, vk_codes.as_ptr(), vk_codes.len() as i32)
== 1
}
}
/// Unregisters a global hotkey.
///
/// Returns `false` when the client is not HWND-backed.
pub fn unregister_hotkey(&self, id: i32) -> bool {
if !self.is_hwnd_client() {
return false;
}
unsafe { ffi::api().TT_HotKey_Unregister(self.ptr.0, id) == 1 }
}
/// Checks if a hotkey is active.
///
/// Returns `false` when the client is not HWND-backed.
pub fn is_hotkey_active(&self, id: i32) -> bool {
if !self.is_hwnd_client() {
return false;
}
unsafe { ffi::api().TT_HotKey_IsActive(self.ptr.0, id) == 1 }
}
/// Installs a hotkey test hook (Windows only).
///
/// # Safety
/// - `hwnd` must be a valid window handle.
/// - `msg` must be a valid message ID routed to `hwnd`.
/// - The window's message loop must remain alive while the hook is installed.
#[cfg(windows)]
pub unsafe fn install_hotkey_test_hook(&self, hwnd: ffi::HWND, msg: u32) -> bool {
if !self.is_hwnd_client() {
return false;
}
unsafe { ffi::api().TT_HotKey_InstallTestHook(self.ptr.0, hwnd, msg) == 1 }
}
/// Removes the hotkey test hook.
///
/// Returns `false` when the client is not HWND-backed.
pub fn remove_hotkey_test_hook(&self) -> bool {
if !self.is_hwnd_client() {
return false;
}
unsafe { ffi::api().TT_HotKey_RemoveTestHook(self.ptr.0) == 1 }
}
/// Returns the string representation of a key.
pub fn get_key_string(&self, vk_code: i32) -> String {
use crate::types::TT_STRLEN;
use crate::utils::strings::tt_buf;
let mut buf = tt_buf::<TT_STRLEN>();
unsafe {
if ffi::api().TT_HotKey_GetKeyString(self.ptr.0, vk_code, buf.as_mut_ptr()) == 1 {
crate::utils::strings::to_string(&buf)
} else {
String::new()
}
}
}
}