thirtyfour/cdp/domains/
input.rs1use serde::Serialize;
4
5use crate::cdp::Cdp;
6use crate::cdp::command::{CdpCommand, Empty};
7use crate::common::protocol::string_enum;
8use crate::error::WebDriverResult;
9
10string_enum! {
11 pub enum KeyEventType {
13 KeyDown = "keyDown",
15 KeyUp = "keyUp",
17 RawKeyDown = "rawKeyDown",
19 Char = "char",
21 }
22}
23
24string_enum! {
25 pub enum MouseEventType {
27 MousePressed = "mousePressed",
29 MouseReleased = "mouseReleased",
31 MouseMoved = "mouseMoved",
33 MouseWheel = "mouseWheel",
35 }
36}
37
38string_enum! {
39 pub enum MouseButton {
41 None = "none",
43 Left = "left",
45 Middle = "middle",
47 Right = "right",
49 Back = "back",
51 Forward = "forward",
53 }
54}
55
56#[derive(Debug, Clone, Serialize)]
58#[serde(rename_all = "camelCase")]
59pub struct DispatchKeyEvent {
60 pub r#type: KeyEventType,
62 #[serde(skip_serializing_if = "Option::is_none")]
65 pub modifiers: Option<u32>,
66 #[serde(skip_serializing_if = "Option::is_none")]
68 pub text: Option<String>,
69 #[serde(skip_serializing_if = "Option::is_none")]
71 pub unmodified_text: Option<String>,
72 #[serde(skip_serializing_if = "Option::is_none")]
74 pub key: Option<String>,
75 #[serde(skip_serializing_if = "Option::is_none")]
77 pub code: Option<String>,
78 #[serde(skip_serializing_if = "Option::is_none")]
80 pub native_virtual_key_code: Option<i32>,
81 #[serde(skip_serializing_if = "Option::is_none")]
83 pub windows_virtual_key_code: Option<i32>,
84 #[serde(skip_serializing_if = "Option::is_none")]
86 pub auto_repeat: Option<bool>,
87 #[serde(skip_serializing_if = "Option::is_none")]
89 pub is_keypad: Option<bool>,
90 #[serde(skip_serializing_if = "Option::is_none")]
92 pub is_system_key: Option<bool>,
93}
94impl CdpCommand for DispatchKeyEvent {
95 const METHOD: &'static str = "Input.dispatchKeyEvent";
96 type Returns = Empty;
97}
98
99#[derive(Debug, Clone, Serialize)]
101#[serde(rename_all = "camelCase")]
102pub struct DispatchMouseEvent {
103 pub r#type: MouseEventType,
105 pub x: f64,
107 pub y: f64,
109 #[serde(skip_serializing_if = "Option::is_none")]
111 pub modifiers: Option<u32>,
112 #[serde(skip_serializing_if = "Option::is_none")]
114 pub button: Option<MouseButton>,
115 #[serde(skip_serializing_if = "Option::is_none")]
117 pub click_count: Option<u32>,
118 #[serde(skip_serializing_if = "Option::is_none")]
120 pub delta_x: Option<f64>,
121 #[serde(skip_serializing_if = "Option::is_none")]
123 pub delta_y: Option<f64>,
124}
125impl CdpCommand for DispatchMouseEvent {
126 const METHOD: &'static str = "Input.dispatchMouseEvent";
127 type Returns = Empty;
128}
129
130#[derive(Debug, Clone, Serialize)]
132pub struct InsertText {
133 pub text: String,
135}
136impl CdpCommand for InsertText {
137 const METHOD: &'static str = "Input.insertText";
138 type Returns = Empty;
139}
140
141#[derive(Debug)]
143pub struct InputDomain<'a> {
144 cdp: &'a Cdp,
145}
146
147impl<'a> InputDomain<'a> {
148 pub(crate) fn new(cdp: &'a Cdp) -> Self {
149 Self {
150 cdp,
151 }
152 }
153
154 pub async fn insert_text(&self, text: impl Into<String>) -> WebDriverResult<()> {
156 self.cdp
157 .send(InsertText {
158 text: text.into(),
159 })
160 .await?;
161 Ok(())
162 }
163}