dora_ssr/dora/
keyboard.rs

1/* Copyright (c) 2016-2025 Li Jin <dragon-fly@qq.com>
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
5The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
7THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
8
9extern "C" {
10	fn keyboard__is_key_down(name: i64) -> i32;
11	fn keyboard__is_key_up(name: i64) -> i32;
12	fn keyboard__is_key_pressed(name: i64) -> i32;
13	fn keyboard_update_ime_pos_hint(win_pos: i64);
14}
15/// An interface for handling keyboard inputs.
16pub struct Keyboard { }
17impl Keyboard {
18	/// Checks whether a key is currently pressed.
19	///
20	/// # Arguments
21	///
22	/// * `name` - The name of the key to check.
23	///
24	/// # Returns
25	///
26	/// * `bool` - `true` if the key is pressed, `false` otherwise.
27	pub(crate) fn _is_key_down(name: &str) -> bool {
28		unsafe { return keyboard__is_key_down(crate::dora::from_string(name)) != 0; }
29	}
30	/// Checks whether a key is currently released.
31	///
32	/// # Arguments
33	///
34	/// * `name` - The name of the key to check.
35	///
36	/// # Returns
37	///
38	/// * `bool` - `true` if the key is released, `false` otherwise.
39	pub(crate) fn _is_key_up(name: &str) -> bool {
40		unsafe { return keyboard__is_key_up(crate::dora::from_string(name)) != 0; }
41	}
42	/// Checks whether a key is currently being pressed.
43	///
44	/// # Arguments
45	///
46	/// * `name` - The name of the key to check.
47	///
48	/// # Returns
49	///
50	/// * `bool` - `true` if the key is being pressed, `false` otherwise.
51	pub(crate) fn _is_key_pressed(name: &str) -> bool {
52		unsafe { return keyboard__is_key_pressed(crate::dora::from_string(name)) != 0; }
53	}
54	/// Updates the input method editor (IME) position hint.
55	///
56	/// # Arguments
57	///
58	/// * `win_pos` - The position of the keyboard window.
59	pub fn update_ime_pos_hint(win_pos: &crate::dora::Vec2) {
60		unsafe { keyboard_update_ime_pos_hint(win_pos.into_i64()); }
61	}
62}