Advertisement
djmango

desktop event struct

Jun 19th, 2024
926
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 2.27 KB | None | 0 0
  1. use chrono::{DateTime, Utc};
  2. use serde::{Deserialize, Serialize};
  3. use sqlx::{FromRow, Type};
  4. use uuid::Uuid;
  5.  
  6. #[derive(Clone, Debug, Serialize, Deserialize, Type)]
  7. #[sqlx(type_name = "mouse_action_enum", rename_all = "lowercase")] // SQL value name
  8. #[serde(rename_all = "lowercase")] // JSON value name
  9. pub enum MouseAction {
  10.     Left,
  11.     Right,
  12.     Middle,
  13.     Button4,
  14.     Button5,
  15. }
  16.  
  17. #[derive(Clone, Debug, Serialize, Deserialize, Type)]
  18. #[sqlx(type_name = "keyboard_action_enum", rename_all = "lowercase")] // SQL value name
  19. #[serde(rename_all = "lowercase")] // JSON value name
  20. pub enum KeyboardAction {
  21.     // Modifier Keys
  22.     Shift,
  23.     Control,
  24.     Alt,
  25.     Meta,
  26.     // Function Keys
  27.     F1,
  28.     F2,
  29.     F3,
  30.     F4,
  31.     F5,
  32.     F6,
  33.     F7,
  34.     F8,
  35.     F9,
  36.     F10,
  37.     F11,
  38.     F12,
  39.     // Alphabet Keys
  40.     A,
  41.     B,
  42.     C,
  43.     D,
  44.     E,
  45.     F,
  46.     G,
  47.     H,
  48.     I,
  49.     J,
  50.     K,
  51.     L,
  52.     M,
  53.     N,
  54.     O,
  55.     P,
  56.     Q,
  57.     R,
  58.     S,
  59.     T,
  60.     U,
  61.     V,
  62.     W,
  63.     X,
  64.     Y,
  65.     Z,
  66.     // Number Keys
  67.     Num0,
  68.     Num1,
  69.     Num2,
  70.     Num3,
  71.     Num4,
  72.     Num5,
  73.     Num6,
  74.     Num7,
  75.     Num8,
  76.     Num9,
  77.     // Navigation Keys
  78.     ArrowUp,
  79.     ArrowDown,
  80.     ArrowLeft,
  81.     ArrowRight,
  82.     Home,
  83.     End,
  84.     PageUp,
  85.     PageDown,
  86.     // Special Keys
  87.     Escape,
  88.     Enter,
  89.     Tab,
  90.     Space,
  91.     Backspace,
  92.     Insert,
  93.     Delete,
  94.     CapsLock,
  95.     NumLock,
  96.     ScrollLock,
  97.     Pause,
  98.     PrintScreen,
  99. }
  100.  
  101. // Desktop event, hence devent
  102.  
  103. #[derive(Debug, Clone, FromRow, Serialize, Deserialize)]
  104. pub struct Devent {
  105.     pub id: Uuid,
  106.     pub user_id: String,
  107.     pub mouse_action: Option<MouseAction>,
  108.     pub keyboard_action: Option<KeyboardAction>,
  109.     pub mouse_x: i32,
  110.     pub mouse_y: i32,
  111.     pub deleted_at: Option<DateTime<Utc>>,
  112.     pub created_at: DateTime<Utc>,
  113.     pub updated_at: DateTime<Utc>,
  114. }
  115.  
  116. impl Default for Devent {
  117.     fn default() -> Self {
  118.         Devent {
  119.             id: Uuid::new_v4(),
  120.             user_id: String::new(),
  121.             mouse_action: None,
  122.             keyboard_action: None,
  123.             mouse_x: 0,
  124.             mouse_y: 0,
  125.             deleted_at: None,
  126.             created_at: Utc::now(),
  127.             updated_at: Utc::now(),
  128.         }
  129.     }
  130. }
  131.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement