diff --git a/CHANGELOG.md b/CHANGELOG.md index a02d1e6e76..9f10136f40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,10 @@ # Change Log ## 1.5.5 -- Fixed to record the screen video more accurately -- Renamed the move_mouse to set_mouse_pos -- Changed the set_mouse_pos and set_btnv to get floating numbers -- Changed the capture scale of the example #7 +- Fixed to record the screen video with collect interval +- Renamed the input setters to setbtn, setbtnv and setmpos +- Changed the input setters to get floating numbers +- Changed the key definitions to SDL2 Keycode base - Updated the example videos - Updated the Pyxel editor videos - Modified the melody of the example #10 diff --git a/lib/engine/src/event.rs b/lib/engine/src/event.rs index 25276824e4..82f504a662 100644 --- a/lib/engine/src/event.rs +++ b/lib/engine/src/event.rs @@ -55,10 +55,10 @@ pub enum Event { // Key events KeyDown { - key: u32, + keycode: u32, }, KeyUp { - key: u32, + keycode: u32, }, TextInput { text: String, diff --git a/lib/engine/src/input.rs b/lib/engine/src/input.rs index 9da062bd11..bef11391e9 100644 --- a/lib/engine/src/input.rs +++ b/lib/engine/src/input.rs @@ -60,21 +60,19 @@ impl Input { Event::Minimized => {} // Key events - Event::KeyDown { key } => { - if (KEY_MIN_VALUE..=KEY_MAX_VALUE).contains(&key) { - self.press_key(key, frame_count); - self.input_keys.push(key); - if let Some(key) = Self::get_common_key(key) { - self.press_key(key, frame_count); - } + Event::KeyDown { keycode } => { + self.press_key(keycode, frame_count); + if let Some(keycode) = to_integrated_key(keycode) { + self.press_key(keycode, frame_count); + } + if is_keyboard_key(keycode) { + self.input_keys.push(keycode); } } - Event::KeyUp { key } => { - if (KEY_MIN_VALUE..=KEY_MAX_VALUE).contains(&key) { - self.release_key(key, frame_count); - if let Some(key) = Self::get_common_key(key) { - self.release_key(key, frame_count); - } + Event::KeyUp { keycode } => { + self.release_key(keycode, frame_count); + if let Some(keycode) = to_integrated_key(keycode) { + self.release_key(keycode, frame_count); } } Event::TextInput { text } => { @@ -132,16 +130,6 @@ impl Input { } } - fn get_common_key(key: Key) -> Option { - match key { - KEY_LSHIFT | KEY_RSHIFT => Some(KEY_SHIFT), - KEY_LCTRL | KEY_RCTRL => Some(KEY_CTRL), - KEY_LALT | KEY_RALT => Some(KEY_ALT), - KEY_LGUI | KEY_RGUI => Some(KEY_GUI), - _ => None, - } - } - fn press_key(&mut self, key: Key, frame_count: u32) { self.key_states .insert(key, KeyState::Pressed { frame_count }); @@ -226,29 +214,29 @@ impl Pyxel { self.input.is_mouse_visible = is_visible; } - pub fn set_btnp(&mut self, key: Key) { - self.input.press_key(key, self.frame_count()); - if (KEY_MIN_VALUE..=KEY_MAX_VALUE).contains(&key) { - self.input.input_keys.push(key); - if let Some(key) = Input::get_common_key(key) { + pub fn setbtn(&mut self, key: Key, key_state: bool) { + if key_state { + self.input.press_key(key, self.frame_count()); + if let Some(key) = to_integrated_key(key) { self.input.press_key(key, self.frame_count()); } - } - } - - pub fn set_btnr(&mut self, key: Key) { - self.input.release_key(key, self.frame_count()); - if let Some(key) = Input::get_common_key(key) { + if is_keyboard_key(key) { + self.input.input_keys.push(key); + } + } else { self.input.release_key(key, self.frame_count()); + if let Some(key) = to_integrated_key(key) { + self.input.release_key(key, self.frame_count()); + } } } - pub fn set_btnv(&mut self, key: Key, key_value: f64) { + pub fn setbtnv(&mut self, key: Key, key_value: f64) { let key_value = as_i32(key_value); self.input.key_values.insert(key, key_value); } - pub fn set_mouse_pos(&mut self, x: f64, y: f64) { + pub fn setmpos(&mut self, x: f64, y: f64) { let x = as_i32(x); let y = as_i32(y); self.input.key_values.insert(MOUSE_POS_X, x); diff --git a/lib/engine/src/key.rs b/lib/engine/src/key.rs index bfbd30eb4d..8732f10b3d 100644 --- a/lib/engine/src/key.rs +++ b/lib/engine/src/key.rs @@ -1,310 +1,317 @@ +use sdl2::keyboard::Keycode; + use crate::types::Key; -// Keyboard -pub const KEY_NONE: Key = 0; -pub const KEY_A: Key = 4; -pub const KEY_B: Key = 5; -pub const KEY_C: Key = 6; -pub const KEY_D: Key = 7; -pub const KEY_E: Key = 8; -pub const KEY_F: Key = 9; -pub const KEY_G: Key = 10; -pub const KEY_H: Key = 11; -pub const KEY_I: Key = 12; -pub const KEY_J: Key = 13; -pub const KEY_K: Key = 14; -pub const KEY_L: Key = 15; -pub const KEY_M: Key = 16; -pub const KEY_N: Key = 17; -pub const KEY_O: Key = 18; -pub const KEY_P: Key = 19; -pub const KEY_Q: Key = 20; -pub const KEY_R: Key = 21; -pub const KEY_S: Key = 22; -pub const KEY_T: Key = 23; -pub const KEY_U: Key = 24; -pub const KEY_V: Key = 25; -pub const KEY_W: Key = 26; -pub const KEY_X: Key = 27; -pub const KEY_Y: Key = 28; -pub const KEY_Z: Key = 29; -pub const KEY_1: Key = 30; -pub const KEY_2: Key = 31; -pub const KEY_3: Key = 32; -pub const KEY_4: Key = 33; -pub const KEY_5: Key = 34; -pub const KEY_6: Key = 35; -pub const KEY_7: Key = 36; -pub const KEY_8: Key = 37; -pub const KEY_9: Key = 38; -pub const KEY_0: Key = 39; -pub const KEY_RETURN: Key = 40; -pub const KEY_ESCAPE: Key = 41; -pub const KEY_BACKSPACE: Key = 42; -pub const KEY_TAB: Key = 43; -pub const KEY_SPACE: Key = 44; -pub const KEY_MINUS: Key = 45; -pub const KEY_EQUALS: Key = 46; -pub const KEY_LEFTBRACKET: Key = 47; -pub const KEY_RIGHTBRACKET: Key = 48; -pub const KEY_BACKSLASH: Key = 49; -pub const KEY_NONUSHASH: Key = 50; -pub const KEY_SEMICOLON: Key = 51; -pub const KEY_APOSTROPHE: Key = 52; -pub const KEY_GRAVE: Key = 53; -pub const KEY_COMMA: Key = 54; -pub const KEY_PERIOD: Key = 55; -pub const KEY_SLASH: Key = 56; -pub const KEY_CAPSLOCK: Key = 57; -pub const KEY_F1: Key = 58; -pub const KEY_F2: Key = 59; -pub const KEY_F3: Key = 60; -pub const KEY_F4: Key = 61; -pub const KEY_F5: Key = 62; -pub const KEY_F6: Key = 63; -pub const KEY_F7: Key = 64; -pub const KEY_F8: Key = 65; -pub const KEY_F9: Key = 66; -pub const KEY_F10: Key = 67; -pub const KEY_F11: Key = 68; -pub const KEY_F12: Key = 69; -pub const KEY_PRINTSCREEN: Key = 70; -pub const KEY_SCROLLLOCK: Key = 71; -pub const KEY_PAUSE: Key = 72; -pub const KEY_INSERT: Key = 73; -pub const KEY_HOME: Key = 74; -pub const KEY_PAGEUP: Key = 75; -pub const KEY_DELETE: Key = 76; -pub const KEY_END: Key = 77; -pub const KEY_PAGEDOWN: Key = 78; -pub const KEY_RIGHT: Key = 79; -pub const KEY_LEFT: Key = 80; -pub const KEY_DOWN: Key = 81; -pub const KEY_UP: Key = 82; -pub const KEY_NUMLOCKCLEAR: Key = 83; -pub const KEY_KP_DIVIDE: Key = 84; -pub const KEY_KP_MULTIPLY: Key = 85; -pub const KEY_KP_MINUS: Key = 86; -pub const KEY_KP_PLUS: Key = 87; -pub const KEY_KP_ENTER: Key = 88; -pub const KEY_KP_1: Key = 89; -pub const KEY_KP_2: Key = 90; -pub const KEY_KP_3: Key = 91; -pub const KEY_KP_4: Key = 92; -pub const KEY_KP_5: Key = 93; -pub const KEY_KP_6: Key = 94; -pub const KEY_KP_7: Key = 95; -pub const KEY_KP_8: Key = 96; -pub const KEY_KP_9: Key = 97; -pub const KEY_KP_0: Key = 98; -pub const KEY_KP_PERIOD: Key = 99; -pub const KEY_NONUSBACKSLASH: Key = 100; -pub const KEY_APPLICATION: Key = 101; -pub const KEY_POWER: Key = 102; -pub const KEY_KP_EQUALS: Key = 103; -pub const KEY_F13: Key = 104; -pub const KEY_F14: Key = 105; -pub const KEY_F15: Key = 106; -pub const KEY_F16: Key = 107; -pub const KEY_F17: Key = 108; -pub const KEY_F18: Key = 109; -pub const KEY_F19: Key = 110; -pub const KEY_F20: Key = 111; -pub const KEY_F21: Key = 112; -pub const KEY_F22: Key = 113; -pub const KEY_F23: Key = 114; -pub const KEY_F24: Key = 115; -pub const KEY_EXECUTE: Key = 116; -pub const KEY_HELP: Key = 117; -pub const KEY_MENU: Key = 118; -pub const KEY_SELECT: Key = 119; -pub const KEY_STOP: Key = 120; -pub const KEY_AGAIN: Key = 121; -pub const KEY_UNDO: Key = 122; -pub const KEY_CUT: Key = 123; -pub const KEY_COPY: Key = 124; -pub const KEY_PASTE: Key = 125; -pub const KEY_FIND: Key = 126; -pub const KEY_MUTE: Key = 127; -pub const KEY_VOLUMEUP: Key = 128; -pub const KEY_VOLUMEDOWN: Key = 129; -pub const KEY_KP_COMMA: Key = 133; -pub const KEY_KP_EQUALSAS400: Key = 134; -pub const KEY_INTERNATIONAL1: Key = 135; -pub const KEY_INTERNATIONAL2: Key = 136; -pub const KEY_INTERNATIONAL3: Key = 137; -pub const KEY_INTERNATIONAL4: Key = 138; -pub const KEY_INTERNATIONAL5: Key = 139; -pub const KEY_INTERNATIONAL6: Key = 140; -pub const KEY_INTERNATIONAL7: Key = 141; -pub const KEY_INTERNATIONAL8: Key = 142; -pub const KEY_INTERNATIONAL9: Key = 143; -pub const KEY_LANG1: Key = 144; -pub const KEY_LANG2: Key = 145; -pub const KEY_LANG3: Key = 146; -pub const KEY_LANG4: Key = 147; -pub const KEY_LANG5: Key = 148; -pub const KEY_LANG6: Key = 149; -pub const KEY_LANG7: Key = 150; -pub const KEY_LANG8: Key = 151; -pub const KEY_LANG9: Key = 152; -pub const KEY_ALTERASE: Key = 153; -pub const KEY_SYSREQ: Key = 154; -pub const KEY_CANCEL: Key = 155; -pub const KEY_CLEAR: Key = 156; -pub const KEY_PRIOR: Key = 157; -pub const KEY_RETURN2: Key = 158; -pub const KEY_SEPARATOR: Key = 159; -pub const KEY_OUT: Key = 160; -pub const KEY_OPER: Key = 161; -pub const KEY_CLEARAGAIN: Key = 162; -pub const KEY_CRSEL: Key = 163; -pub const KEY_EXSEL: Key = 164; -pub const KEY_KP_00: Key = 176; -pub const KEY_KP_000: Key = 177; -pub const KEY_THOUSANDSSEPARATOR: Key = 178; -pub const KEY_DECIMALSEPARATOR: Key = 179; -pub const KEY_CURRENCYUNIT: Key = 180; -pub const KEY_CURRENCYSUBUNIT: Key = 181; -pub const KEY_KP_LEFTPAREN: Key = 182; -pub const KEY_KP_RIGHTPAREN: Key = 183; -pub const KEY_KP_LEFTBRACE: Key = 184; -pub const KEY_KP_RIGHTBRACE: Key = 185; -pub const KEY_KP_TAB: Key = 186; -pub const KEY_KP_BACKSPACE: Key = 187; -pub const KEY_KP_A: Key = 188; -pub const KEY_KP_B: Key = 189; -pub const KEY_KP_C: Key = 190; -pub const KEY_KP_D: Key = 191; -pub const KEY_KP_E: Key = 192; -pub const KEY_KP_F: Key = 193; -pub const KEY_KP_XOR: Key = 194; -pub const KEY_KP_POWER: Key = 195; -pub const KEY_KP_PERCENT: Key = 196; -pub const KEY_KP_LESS: Key = 197; -pub const KEY_KP_GREATER: Key = 198; -pub const KEY_KP_AMPERSAND: Key = 199; -pub const KEY_KP_DBLAMPERSAND: Key = 200; -pub const KEY_KP_VERTICALBAR: Key = 201; -pub const KEY_KP_DBLVERTICALBAR: Key = 202; -pub const KEY_KP_COLON: Key = 203; -pub const KEY_KP_HASH: Key = 204; -pub const KEY_KP_SPACE: Key = 205; -pub const KEY_KP_AT: Key = 206; -pub const KEY_KP_EXCLAM: Key = 207; -pub const KEY_KP_MEMSTORE: Key = 208; -pub const KEY_KP_MEMRECALL: Key = 209; -pub const KEY_KP_MEMCLEAR: Key = 210; -pub const KEY_KP_MEMADD: Key = 211; -pub const KEY_KP_MEMSUBTRACT: Key = 212; -pub const KEY_KP_MEMMULTIPLY: Key = 213; -pub const KEY_KP_MEMDIVIDE: Key = 214; -pub const KEY_KP_PLUSMINUS: Key = 215; -pub const KEY_KP_CLEAR: Key = 216; -pub const KEY_KP_CLEARENTRY: Key = 217; -pub const KEY_KP_BINARY: Key = 218; -pub const KEY_KP_OCTAL: Key = 219; -pub const KEY_KP_DECIMAL: Key = 220; -pub const KEY_KP_HEXADECIMAL: Key = 221; -pub const KEY_LCTRL: Key = 224; -pub const KEY_LSHIFT: Key = 225; -pub const KEY_LALT: Key = 226; -pub const KEY_LGUI: Key = 227; -pub const KEY_RCTRL: Key = 228; -pub const KEY_RSHIFT: Key = 229; -pub const KEY_RALT: Key = 230; -pub const KEY_RGUI: Key = 231; -pub const KEY_MODE: Key = 257; -pub const KEY_AUDIONEXT: Key = 258; -pub const KEY_AUDIOPREV: Key = 259; -pub const KEY_AUDIOSTOP: Key = 260; -pub const KEY_AUDIOPLAY: Key = 261; -pub const KEY_AUDIOMUTE: Key = 262; -pub const KEY_MEDIASELECT: Key = 263; -pub const KEY_WWW: Key = 264; -pub const KEY_MAIL: Key = 265; -pub const KEY_CALCULATOR: Key = 266; -pub const KEY_COMPUTER: Key = 267; -pub const KEY_AC_SEARCH: Key = 268; -pub const KEY_AC_HOME: Key = 269; -pub const KEY_AC_BACK: Key = 270; -pub const KEY_AC_FORWARD: Key = 271; -pub const KEY_AC_STOP: Key = 272; -pub const KEY_AC_REFRESH: Key = 273; -pub const KEY_AC_BOOKMARKS: Key = 274; -pub const KEY_BRIGHTNESSDOWN: Key = 275; -pub const KEY_BRIGHTNESSUP: Key = 276; -pub const KEY_DISPLAYSWITCH: Key = 277; -pub const KEY_KBDILLUMTOGGLE: Key = 278; -pub const KEY_KBDILLUMDOWN: Key = 279; -pub const KEY_KBDILLUMUP: Key = 280; -pub const KEY_EJECT: Key = 281; -pub const KEY_SLEEP: Key = 282; -pub const KEY_APP1: Key = 283; -pub const KEY_APP2: Key = 284; -pub const KEY_AUDIOREWIND: Key = 285; -pub const KEY_AUDIOFASTFORWARD: Key = 286; -pub const KEY_MIN_VALUE: Key = KEY_A; // not to export -pub const KEY_MAX_VALUE: Key = KEY_AUDIOFASTFORWARD; // not to export -pub const KEY_SHIFT: Key = 300; -pub const KEY_CTRL: Key = 301; -pub const KEY_ALT: Key = 302; -pub const KEY_GUI: Key = 303; +// Keyboard (based on rust-sdl2/src/sdl2/keyboard/keycode.rs) +pub const KEY_BACKSPACE: Key = Keycode::Backspace as Key; +pub const KEY_TAB: Key = Keycode::Tab as Key; +pub const KEY_RETURN: Key = Keycode::Return as Key; +pub const KEY_ESCAPE: Key = Keycode::Escape as Key; +pub const KEY_SPACE: Key = Keycode::Space as Key; +pub const KEY_EXCLAIM: Key = Keycode::Exclaim as Key; +pub const KEY_QUOTEDBL: Key = Keycode::Quotedbl as Key; +pub const KEY_HASH: Key = Keycode::Hash as Key; +pub const KEY_DOLLAR: Key = Keycode::Dollar as Key; +pub const KEY_PERCENT: Key = Keycode::Percent as Key; +pub const KEY_AMPERSAND: Key = Keycode::Ampersand as Key; +pub const KEY_QUOTE: Key = Keycode::Quote as Key; +pub const KEY_LEFTPAREN: Key = Keycode::LeftParen as Key; +pub const KEY_RIGHTPAREN: Key = Keycode::RightParen as Key; +pub const KEY_ASTERISK: Key = Keycode::Asterisk as Key; +pub const KEY_PLUS: Key = Keycode::Plus as Key; +pub const KEY_COMMA: Key = Keycode::Comma as Key; +pub const KEY_MINUS: Key = Keycode::Minus as Key; +pub const KEY_PERIOD: Key = Keycode::Period as Key; +pub const KEY_SLASH: Key = Keycode::Slash as Key; +pub const KEY_0: Key = Keycode::Num0 as Key; +pub const KEY_1: Key = Keycode::Num1 as Key; +pub const KEY_2: Key = Keycode::Num2 as Key; +pub const KEY_3: Key = Keycode::Num3 as Key; +pub const KEY_4: Key = Keycode::Num4 as Key; +pub const KEY_5: Key = Keycode::Num5 as Key; +pub const KEY_6: Key = Keycode::Num6 as Key; +pub const KEY_7: Key = Keycode::Num7 as Key; +pub const KEY_8: Key = Keycode::Num8 as Key; +pub const KEY_9: Key = Keycode::Num9 as Key; +pub const KEY_COLON: Key = Keycode::Colon as Key; +pub const KEY_SEMICOLON: Key = Keycode::Semicolon as Key; +pub const KEY_LESS: Key = Keycode::Less as Key; +pub const KEY_EQUALS: Key = Keycode::Equals as Key; +pub const KEY_GREATER: Key = Keycode::Greater as Key; +pub const KEY_QUESTION: Key = Keycode::Question as Key; +pub const KEY_AT: Key = Keycode::At as Key; +pub const KEY_LEFTBRACKET: Key = Keycode::LeftBracket as Key; +pub const KEY_BACKSLASH: Key = Keycode::Backslash as Key; +pub const KEY_RIGHTBRACKET: Key = Keycode::RightBracket as Key; +pub const KEY_CARET: Key = Keycode::Caret as Key; +pub const KEY_UNDERSCORE: Key = Keycode::Underscore as Key; +pub const KEY_BACKQUOTE: Key = Keycode::Backquote as Key; +pub const KEY_A: Key = Keycode::A as Key; +pub const KEY_B: Key = Keycode::B as Key; +pub const KEY_C: Key = Keycode::C as Key; +pub const KEY_D: Key = Keycode::D as Key; +pub const KEY_E: Key = Keycode::E as Key; +pub const KEY_F: Key = Keycode::F as Key; +pub const KEY_G: Key = Keycode::G as Key; +pub const KEY_H: Key = Keycode::H as Key; +pub const KEY_I: Key = Keycode::I as Key; +pub const KEY_J: Key = Keycode::J as Key; +pub const KEY_K: Key = Keycode::K as Key; +pub const KEY_L: Key = Keycode::L as Key; +pub const KEY_M: Key = Keycode::M as Key; +pub const KEY_N: Key = Keycode::N as Key; +pub const KEY_O: Key = Keycode::O as Key; +pub const KEY_P: Key = Keycode::P as Key; +pub const KEY_Q: Key = Keycode::Q as Key; +pub const KEY_R: Key = Keycode::R as Key; +pub const KEY_S: Key = Keycode::S as Key; +pub const KEY_T: Key = Keycode::T as Key; +pub const KEY_U: Key = Keycode::U as Key; +pub const KEY_V: Key = Keycode::V as Key; +pub const KEY_W: Key = Keycode::W as Key; +pub const KEY_X: Key = Keycode::X as Key; +pub const KEY_Y: Key = Keycode::Y as Key; +pub const KEY_Z: Key = Keycode::Z as Key; +pub const KEY_DELETE: Key = Keycode::Delete as Key; +pub const KEY_CAPSLOCK: Key = Keycode::CapsLock as Key; +pub const KEY_F1: Key = Keycode::F1 as Key; +pub const KEY_F2: Key = Keycode::F2 as Key; +pub const KEY_F3: Key = Keycode::F3 as Key; +pub const KEY_F4: Key = Keycode::F4 as Key; +pub const KEY_F5: Key = Keycode::F5 as Key; +pub const KEY_F6: Key = Keycode::F6 as Key; +pub const KEY_F7: Key = Keycode::F7 as Key; +pub const KEY_F8: Key = Keycode::F8 as Key; +pub const KEY_F9: Key = Keycode::F9 as Key; +pub const KEY_F10: Key = Keycode::F10 as Key; +pub const KEY_F11: Key = Keycode::F11 as Key; +pub const KEY_F12: Key = Keycode::F12 as Key; +pub const KEY_PRINTSCREEN: Key = Keycode::PrintScreen as Key; +pub const KEY_SCROLLLOCK: Key = Keycode::ScrollLock as Key; +pub const KEY_PAUSE: Key = Keycode::Pause as Key; +pub const KEY_INSERT: Key = Keycode::Insert as Key; +pub const KEY_HOME: Key = Keycode::Home as Key; +pub const KEY_PAGEUP: Key = Keycode::PageUp as Key; +pub const KEY_END: Key = Keycode::End as Key; +pub const KEY_PAGEDOWN: Key = Keycode::PageDown as Key; +pub const KEY_RIGHT: Key = Keycode::Right as Key; +pub const KEY_LEFT: Key = Keycode::Left as Key; +pub const KEY_DOWN: Key = Keycode::Down as Key; +pub const KEY_UP: Key = Keycode::Up as Key; +pub const KEY_NUMLOCKCLEAR: Key = Keycode::NumLockClear as Key; +pub const KEY_KP_DIVIDE: Key = Keycode::KpDivide as Key; +pub const KEY_KP_MULTIPLY: Key = Keycode::KpMultiply as Key; +pub const KEY_KP_MINUS: Key = Keycode::KpMinus as Key; +pub const KEY_KP_PLUS: Key = Keycode::KpPlus as Key; +pub const KEY_KP_ENTER: Key = Keycode::KpEnter as Key; +pub const KEY_KP_1: Key = Keycode::Kp1 as Key; +pub const KEY_KP_2: Key = Keycode::Kp2 as Key; +pub const KEY_KP_3: Key = Keycode::Kp3 as Key; +pub const KEY_KP_4: Key = Keycode::Kp4 as Key; +pub const KEY_KP_5: Key = Keycode::Kp5 as Key; +pub const KEY_KP_6: Key = Keycode::Kp6 as Key; +pub const KEY_KP_7: Key = Keycode::Kp7 as Key; +pub const KEY_KP_8: Key = Keycode::Kp8 as Key; +pub const KEY_KP_9: Key = Keycode::Kp9 as Key; +pub const KEY_KP_0: Key = Keycode::Kp0 as Key; +pub const KEY_KP_PERIOD: Key = Keycode::KpPeriod as Key; +pub const KEY_APPLICATION: Key = Keycode::Application as Key; +pub const KEY_POWER: Key = Keycode::Power as Key; +pub const KEY_KP_EQUALS: Key = Keycode::KpEquals as Key; +pub const KEY_F13: Key = Keycode::F13 as Key; +pub const KEY_F14: Key = Keycode::F14 as Key; +pub const KEY_F15: Key = Keycode::F15 as Key; +pub const KEY_F16: Key = Keycode::F16 as Key; +pub const KEY_F17: Key = Keycode::F17 as Key; +pub const KEY_F18: Key = Keycode::F18 as Key; +pub const KEY_F19: Key = Keycode::F19 as Key; +pub const KEY_F20: Key = Keycode::F20 as Key; +pub const KEY_F21: Key = Keycode::F21 as Key; +pub const KEY_F22: Key = Keycode::F22 as Key; +pub const KEY_F23: Key = Keycode::F23 as Key; +pub const KEY_F24: Key = Keycode::F24 as Key; +pub const KEY_EXECUTE: Key = Keycode::Execute as Key; +pub const KEY_HELP: Key = Keycode::Help as Key; +pub const KEY_MENU: Key = Keycode::Menu as Key; +pub const KEY_SELECT: Key = Keycode::Select as Key; +pub const KEY_STOP: Key = Keycode::Stop as Key; +pub const KEY_AGAIN: Key = Keycode::Again as Key; +pub const KEY_UNDO: Key = Keycode::Undo as Key; +pub const KEY_CUT: Key = Keycode::Cut as Key; +pub const KEY_COPY: Key = Keycode::Copy as Key; +pub const KEY_PASTE: Key = Keycode::Paste as Key; +pub const KEY_FIND: Key = Keycode::Find as Key; +pub const KEY_MUTE: Key = Keycode::Mute as Key; +pub const KEY_VOLUMEUP: Key = Keycode::VolumeUp as Key; +pub const KEY_VOLUMEDOWN: Key = Keycode::VolumeDown as Key; +pub const KEY_KP_COMMA: Key = Keycode::KpComma as Key; +pub const KEY_KP_EQUALSAS400: Key = Keycode::KpEqualsAS400 as Key; +pub const KEY_ALTERASE: Key = Keycode::AltErase as Key; +pub const KEY_SYSREQ: Key = Keycode::Sysreq as Key; +pub const KEY_CANCEL: Key = Keycode::Cancel as Key; +pub const KEY_CLEAR: Key = Keycode::Clear as Key; +pub const KEY_PRIOR: Key = Keycode::Prior as Key; +pub const KEY_RETURN2: Key = Keycode::Return2 as Key; +pub const KEY_SEPARATOR: Key = Keycode::Separator as Key; +pub const KEY_OUT: Key = Keycode::Out as Key; +pub const KEY_OPER: Key = Keycode::Oper as Key; +pub const KEY_CLEARAGAIN: Key = Keycode::ClearAgain as Key; +pub const KEY_CRSEL: Key = Keycode::CrSel as Key; +pub const KEY_EXSEL: Key = Keycode::ExSel as Key; +pub const KEY_KP_00: Key = Keycode::Kp00 as Key; +pub const KEY_KP_000: Key = Keycode::Kp000 as Key; +pub const KEY_THOUSANDSSEPARATOR: Key = Keycode::ThousandsSeparator as Key; +pub const KEY_DECIMALSEPARATOR: Key = Keycode::DecimalSeparator as Key; +pub const KEY_CURRENCYUNIT: Key = Keycode::CurrencyUnit as Key; +pub const KEY_CURRENCYSUBUNIT: Key = Keycode::CurrencySubUnit as Key; +pub const KEY_KP_LEFTPAREN: Key = Keycode::KpLeftParen as Key; +pub const KEY_KP_RIGHTPAREN: Key = Keycode::KpRightParen as Key; +pub const KEY_KP_LEFTBRACE: Key = Keycode::KpLeftBrace as Key; +pub const KEY_KP_RIGHTBRACE: Key = Keycode::KpRightBrace as Key; +pub const KEY_KP_TAB: Key = Keycode::KpTab as Key; +pub const KEY_KP_BACKSPACE: Key = Keycode::KpBackspace as Key; +pub const KEY_KP_A: Key = Keycode::KpA as Key; +pub const KEY_KP_B: Key = Keycode::KpB as Key; +pub const KEY_KP_C: Key = Keycode::KpC as Key; +pub const KEY_KP_D: Key = Keycode::KpD as Key; +pub const KEY_KP_E: Key = Keycode::KpE as Key; +pub const KEY_KP_F: Key = Keycode::KpF as Key; +pub const KEY_KP_XOR: Key = Keycode::KpXor as Key; +pub const KEY_KP_POWER: Key = Keycode::KpPower as Key; +pub const KEY_KP_PERCENT: Key = Keycode::KpPercent as Key; +pub const KEY_KP_LESS: Key = Keycode::KpLess as Key; +pub const KEY_KP_GREATER: Key = Keycode::KpGreater as Key; +pub const KEY_KP_AMPERSAND: Key = Keycode::KpAmpersand as Key; +pub const KEY_KP_DBLAMPERSAND: Key = Keycode::KpDblAmpersand as Key; +pub const KEY_KP_VERTICALBAR: Key = Keycode::KpVerticalBar as Key; +pub const KEY_KP_DBLVERTICALBAR: Key = Keycode::KpDblVerticalBar as Key; +pub const KEY_KP_COLON: Key = Keycode::KpColon as Key; +pub const KEY_KP_HASH: Key = Keycode::KpHash as Key; +pub const KEY_KP_SPACE: Key = Keycode::KpSpace as Key; +pub const KEY_KP_AT: Key = Keycode::KpAt as Key; +pub const KEY_KP_EXCLAM: Key = Keycode::KpExclam as Key; +pub const KEY_KP_MEMSTORE: Key = Keycode::KpMemStore as Key; +pub const KEY_KP_MEMRECALL: Key = Keycode::KpMemRecall as Key; +pub const KEY_KP_MEMCLEAR: Key = Keycode::KpMemClear as Key; +pub const KEY_KP_MEMADD: Key = Keycode::KpMemAdd as Key; +pub const KEY_KP_MEMSUBTRACT: Key = Keycode::KpMemSubtract as Key; +pub const KEY_KP_MEMMULTIPLY: Key = Keycode::KpMemMultiply as Key; +pub const KEY_KP_MEMDIVIDE: Key = Keycode::KpMemDivide as Key; +pub const KEY_KP_PLUSMINUS: Key = Keycode::KpPlusMinus as Key; +pub const KEY_KP_CLEAR: Key = Keycode::KpClear as Key; +pub const KEY_KP_CLEARENTRY: Key = Keycode::KpClearEntry as Key; +pub const KEY_KP_BINARY: Key = Keycode::KpBinary as Key; +pub const KEY_KP_OCTAL: Key = Keycode::KpOctal as Key; +pub const KEY_KP_DECIMAL: Key = Keycode::KpDecimal as Key; +pub const KEY_KP_HEXADECIMAL: Key = Keycode::KpHexadecimal as Key; +pub const KEY_LCTRL: Key = Keycode::LCtrl as Key; +pub const KEY_LSHIFT: Key = Keycode::LShift as Key; +pub const KEY_LALT: Key = Keycode::LAlt as Key; +pub const KEY_LGUI: Key = Keycode::LGui as Key; +pub const KEY_RCTRL: Key = Keycode::RCtrl as Key; +pub const KEY_RSHIFT: Key = Keycode::RShift as Key; +pub const KEY_RALT: Key = Keycode::RAlt as Key; +pub const KEY_RGUI: Key = Keycode::RGui as Key; +pub const KEY_MODE: Key = Keycode::Mode as Key; +pub const KEY_AUDIONEXT: Key = Keycode::AudioNext as Key; +pub const KEY_AUDIOPREV: Key = Keycode::AudioPrev as Key; +pub const KEY_AUDIOSTOP: Key = Keycode::AudioStop as Key; +pub const KEY_AUDIOPLAY: Key = Keycode::AudioPlay as Key; +pub const KEY_AUDIOMUTE: Key = Keycode::AudioMute as Key; +pub const KEY_MEDIASELECT: Key = Keycode::MediaSelect as Key; +pub const KEY_WWW: Key = Keycode::Www as Key; +pub const KEY_MAIL: Key = Keycode::Mail as Key; +pub const KEY_CALCULATOR: Key = Keycode::Calculator as Key; +pub const KEY_COMPUTER: Key = Keycode::Computer as Key; +pub const KEY_AC_SEARCH: Key = Keycode::AcSearch as Key; +pub const KEY_AC_HOME: Key = Keycode::AcHome as Key; +pub const KEY_AC_BACK: Key = Keycode::AcBack as Key; +pub const KEY_AC_FORWARD: Key = Keycode::AcForward as Key; +pub const KEY_AC_STOP: Key = Keycode::AcStop as Key; +pub const KEY_AC_REFRESH: Key = Keycode::AcRefresh as Key; +pub const KEY_AC_BOOKMARKS: Key = Keycode::AcBookmarks as Key; +pub const KEY_BRIGHTNESSDOWN: Key = Keycode::BrightnessDown as Key; +pub const KEY_BRIGHTNESSUP: Key = Keycode::BrightnessUp as Key; +pub const KEY_DISPLAYSWITCH: Key = Keycode::DisplaySwitch as Key; +pub const KEY_KBDILLUMTOGGLE: Key = Keycode::KbdIllumToggle as Key; +pub const KEY_KBDILLUMDOWN: Key = Keycode::KbdIllumDown as Key; +pub const KEY_KBDILLUMUP: Key = Keycode::KbdIllumUp as Key; +pub const KEY_EJECT: Key = Keycode::Eject as Key; +pub const KEY_SLEEP: Key = Keycode::Sleep as Key; +pub const KEY_NONE: Key = 10000; +pub const KEY_SHIFT: Key = 10001; +pub const KEY_CTRL: Key = 10002; +pub const KEY_ALT: Key = 10003; +pub const KEY_GUI: Key = 10004; // Mouse -pub const MOUSE_POS_X: Key = 400; -pub const MOUSE_POS_Y: Key = 401; -pub const MOUSE_WHEEL_X: Key = 402; -pub const MOUSE_WHEEL_Y: Key = 403; -pub const MOUSE_BUTTON_LEFT: Key = 450; -pub const MOUSE_BUTTON_MIDDLE: Key = 451; -pub const MOUSE_BUTTON_RIGHT: Key = 452; -pub const MOUSE_BUTTON_X1: Key = 453; -pub const MOUSE_BUTTON_X2: Key = 454; -pub const MOUSE_BUTTON_UNKNOWN: Key = 455; +pub const MOUSE_POS_X: Key = 20000; +pub const MOUSE_POS_Y: Key = 20001; +pub const MOUSE_WHEEL_X: Key = 20002; +pub const MOUSE_WHEEL_Y: Key = 20003; +pub const MOUSE_BUTTON_LEFT: Key = 20004; +pub const MOUSE_BUTTON_MIDDLE: Key = 20005; +pub const MOUSE_BUTTON_RIGHT: Key = 20006; +pub const MOUSE_BUTTON_X1: Key = 20007; +pub const MOUSE_BUTTON_X2: Key = 20008; +pub const MOUSE_BUTTON_UNKNOWN: Key = 20009; // Gamepad1 -pub const GAMEPAD1_AXIS_LEFTX: Key = 500; -pub const GAMEPAD1_AXIS_LEFTY: Key = 501; -pub const GAMEPAD1_AXIS_RIGHTX: Key = 502; -pub const GAMEPAD1_AXIS_RIGHTY: Key = 503; -pub const GAMEPAD1_AXIS_TRIGGERLEFT: Key = 504; -pub const GAMEPAD1_AXIS_TRIGGERRIGHT: Key = 505; -pub const GAMEPAD1_BUTTON_A: Key = 550; -pub const GAMEPAD1_BUTTON_B: Key = 551; -pub const GAMEPAD1_BUTTON_X: Key = 552; -pub const GAMEPAD1_BUTTON_Y: Key = 553; -pub const GAMEPAD1_BUTTON_BACK: Key = 554; -pub const GAMEPAD1_BUTTON_GUIDE: Key = 555; -pub const GAMEPAD1_BUTTON_START: Key = 556; -pub const GAMEPAD1_BUTTON_LEFTSTICK: Key = 557; -pub const GAMEPAD1_BUTTON_RIGHTSTICK: Key = 558; -pub const GAMEPAD1_BUTTON_LEFTSHOULDER: Key = 559; -pub const GAMEPAD1_BUTTON_RIGHTSHOULDER: Key = 560; -pub const GAMEPAD1_BUTTON_DPAD_UP: Key = 561; -pub const GAMEPAD1_BUTTON_DPAD_DOWN: Key = 562; -pub const GAMEPAD1_BUTTON_DPAD_LEFT: Key = 563; -pub const GAMEPAD1_BUTTON_DPAD_RIGHT: Key = 564; +pub const GAMEPAD1_AXIS_LEFTX: Key = 30000; +pub const GAMEPAD1_AXIS_LEFTY: Key = 30001; +pub const GAMEPAD1_AXIS_RIGHTX: Key = 30002; +pub const GAMEPAD1_AXIS_RIGHTY: Key = 30003; +pub const GAMEPAD1_AXIS_TRIGGERLEFT: Key = 30004; +pub const GAMEPAD1_AXIS_TRIGGERRIGHT: Key = 30005; +pub const GAMEPAD1_BUTTON_A: Key = 31000; +pub const GAMEPAD1_BUTTON_B: Key = 31001; +pub const GAMEPAD1_BUTTON_X: Key = 31002; +pub const GAMEPAD1_BUTTON_Y: Key = 31003; +pub const GAMEPAD1_BUTTON_BACK: Key = 31004; +pub const GAMEPAD1_BUTTON_GUIDE: Key = 31005; +pub const GAMEPAD1_BUTTON_START: Key = 31006; +pub const GAMEPAD1_BUTTON_LEFTSTICK: Key = 31007; +pub const GAMEPAD1_BUTTON_RIGHTSTICK: Key = 31008; +pub const GAMEPAD1_BUTTON_LEFTSHOULDER: Key = 31009; +pub const GAMEPAD1_BUTTON_RIGHTSHOULDER: Key = 31010; +pub const GAMEPAD1_BUTTON_DPAD_UP: Key = 31011; +pub const GAMEPAD1_BUTTON_DPAD_DOWN: Key = 31012; +pub const GAMEPAD1_BUTTON_DPAD_LEFT: Key = 31013; +pub const GAMEPAD1_BUTTON_DPAD_RIGHT: Key = 31014; // Gamepad2 -pub const GAMEPAD2_AXIS_LEFTX: Key = 600; -pub const GAMEPAD2_AXIS_LEFTY: Key = 601; -pub const GAMEPAD2_AXIS_RIGHTX: Key = 602; -pub const GAMEPAD2_AXIS_RIGHTY: Key = 603; -pub const GAMEPAD2_AXIS_TRIGGERLEFT: Key = 604; -pub const GAMEPAD2_AXIS_TRIGGERRIGHT: Key = 605; -pub const GAMEPAD2_BUTTON_A: Key = 650; -pub const GAMEPAD2_BUTTON_B: Key = 651; -pub const GAMEPAD2_BUTTON_X: Key = 652; -pub const GAMEPAD2_BUTTON_Y: Key = 653; -pub const GAMEPAD2_BUTTON_BACK: Key = 654; -pub const GAMEPAD2_BUTTON_GUIDE: Key = 655; -pub const GAMEPAD2_BUTTON_START: Key = 656; -pub const GAMEPAD2_BUTTON_LEFTSTICK: Key = 657; -pub const GAMEPAD2_BUTTON_RIGHTSTICK: Key = 658; -pub const GAMEPAD2_BUTTON_LEFTSHOULDER: Key = 659; -pub const GAMEPAD2_BUTTON_RIGHTSHOULDER: Key = 660; -pub const GAMEPAD2_BUTTON_DPAD_UP: Key = 661; -pub const GAMEPAD2_BUTTON_DPAD_DOWN: Key = 662; -pub const GAMEPAD2_BUTTON_DPAD_LEFT: Key = 663; -pub const GAMEPAD2_BUTTON_DPAD_RIGHT: Key = 664; +pub const GAMEPAD2_AXIS_LEFTX: Key = 40000; +pub const GAMEPAD2_AXIS_LEFTY: Key = 40001; +pub const GAMEPAD2_AXIS_RIGHTX: Key = 40002; +pub const GAMEPAD2_AXIS_RIGHTY: Key = 40003; +pub const GAMEPAD2_AXIS_TRIGGERLEFT: Key = 40004; +pub const GAMEPAD2_AXIS_TRIGGERRIGHT: Key = 40005; +pub const GAMEPAD2_BUTTON_A: Key = 41000; +pub const GAMEPAD2_BUTTON_B: Key = 41001; +pub const GAMEPAD2_BUTTON_X: Key = 41002; +pub const GAMEPAD2_BUTTON_Y: Key = 41003; +pub const GAMEPAD2_BUTTON_BACK: Key = 41004; +pub const GAMEPAD2_BUTTON_GUIDE: Key = 41005; +pub const GAMEPAD2_BUTTON_START: Key = 41006; +pub const GAMEPAD2_BUTTON_LEFTSTICK: Key = 41007; +pub const GAMEPAD2_BUTTON_RIGHTSTICK: Key = 41008; +pub const GAMEPAD2_BUTTON_LEFTSHOULDER: Key = 41009; +pub const GAMEPAD2_BUTTON_RIGHTSHOULDER: Key = 41010; +pub const GAMEPAD2_BUTTON_DPAD_UP: Key = 41011; +pub const GAMEPAD2_BUTTON_DPAD_DOWN: Key = 41012; +pub const GAMEPAD2_BUTTON_DPAD_LEFT: Key = 41013; +pub const GAMEPAD2_BUTTON_DPAD_RIGHT: Key = 41014; + +pub fn is_keyboard_key(key: Key) -> bool { + !(MOUSE_POS_X..=GAMEPAD2_BUTTON_DPAD_RIGHT).contains(&key) +} + +pub fn to_integrated_key(key: Key) -> Option { + match key { + KEY_LSHIFT | KEY_RSHIFT => Some(KEY_SHIFT), + KEY_LCTRL | KEY_RCTRL => Some(KEY_CTRL), + KEY_LALT | KEY_RALT => Some(KEY_ALT), + KEY_LGUI | KEY_RGUI => Some(KEY_GUI), + _ => None, + } +} diff --git a/lib/engine/src/sdl2.rs b/lib/engine/src/sdl2.rs index 517c753ac2..579fe62b09 100644 --- a/lib/engine/src/sdl2.rs +++ b/lib/engine/src/sdl2.rs @@ -199,16 +199,16 @@ impl Platform for Sdl2 { // Key events SdlEvent::KeyDown { - scancode: Some(scancode), + keycode: Some(keycode), .. } => Event::KeyDown { - key: scancode as u32, + keycode: keycode as u32, }, SdlEvent::KeyUp { - scancode: Some(scancode), + keycode: Some(keycode), .. } => Event::KeyUp { - key: scancode as u32, + keycode: keycode as u32, }, SdlEvent::TextInput { text, .. } => Event::TextInput { text }, diff --git a/lib/engine/tests/test_pyxel.rs b/lib/engine/tests/test_pyxel.rs index 1e58a2423b..4693f18b36 100644 --- a/lib/engine/tests/test_pyxel.rs +++ b/lib/engine/tests/test_pyxel.rs @@ -10,7 +10,7 @@ impl App { let app = App { x: 0.0, y: 0.0 }; pyxel.mouse(true); - pyxel.set_mouse_pos(10.0, 10.0); + pyxel.setmpos(10.0, 10.0); pyxel.image(0).lock().set( 0, diff --git a/lib/wrapper/src/constant_wrapper.rs b/lib/wrapper/src/constant_wrapper.rs index 94b89df574..74e2c2e50f 100644 --- a/lib/wrapper/src/constant_wrapper.rs +++ b/lib/wrapper/src/constant_wrapper.rs @@ -53,7 +53,49 @@ pub fn add_module_constants(m: &PyModule) -> PyResult<()> { add_constant!(EFFECT_FADEOUT)?; // Key - add_constant!(KEY_NONE)?; + add_constant!(KEY_BACKSPACE)?; + add_constant!(KEY_TAB)?; + add_constant!(KEY_RETURN)?; + add_constant!(KEY_ESCAPE)?; + add_constant!(KEY_SPACE)?; + add_constant!(KEY_EXCLAIM)?; + add_constant!(KEY_QUOTEDBL)?; + add_constant!(KEY_HASH)?; + add_constant!(KEY_DOLLAR)?; + add_constant!(KEY_PERCENT)?; + add_constant!(KEY_AMPERSAND)?; + add_constant!(KEY_QUOTE)?; + add_constant!(KEY_LEFTPAREN)?; + add_constant!(KEY_RIGHTPAREN)?; + add_constant!(KEY_ASTERISK)?; + add_constant!(KEY_PLUS)?; + add_constant!(KEY_COMMA)?; + add_constant!(KEY_MINUS)?; + add_constant!(KEY_PERIOD)?; + add_constant!(KEY_SLASH)?; + add_constant!(KEY_0)?; + add_constant!(KEY_1)?; + add_constant!(KEY_2)?; + add_constant!(KEY_3)?; + add_constant!(KEY_4)?; + add_constant!(KEY_5)?; + add_constant!(KEY_6)?; + add_constant!(KEY_7)?; + add_constant!(KEY_8)?; + add_constant!(KEY_9)?; + add_constant!(KEY_COLON)?; + add_constant!(KEY_SEMICOLON)?; + add_constant!(KEY_LESS)?; + add_constant!(KEY_EQUALS)?; + add_constant!(KEY_GREATER)?; + add_constant!(KEY_QUESTION)?; + add_constant!(KEY_AT)?; + add_constant!(KEY_LEFTBRACKET)?; + add_constant!(KEY_BACKSLASH)?; + add_constant!(KEY_RIGHTBRACKET)?; + add_constant!(KEY_CARET)?; + add_constant!(KEY_UNDERSCORE)?; + add_constant!(KEY_BACKQUOTE)?; add_constant!(KEY_A)?; add_constant!(KEY_B)?; add_constant!(KEY_C)?; @@ -80,33 +122,7 @@ pub fn add_module_constants(m: &PyModule) -> PyResult<()> { add_constant!(KEY_X)?; add_constant!(KEY_Y)?; add_constant!(KEY_Z)?; - add_constant!(KEY_1)?; - add_constant!(KEY_2)?; - add_constant!(KEY_3)?; - add_constant!(KEY_4)?; - add_constant!(KEY_5)?; - add_constant!(KEY_6)?; - add_constant!(KEY_7)?; - add_constant!(KEY_8)?; - add_constant!(KEY_9)?; - add_constant!(KEY_0)?; - add_constant!(KEY_RETURN)?; - add_constant!(KEY_ESCAPE)?; - add_constant!(KEY_BACKSPACE)?; - add_constant!(KEY_TAB)?; - add_constant!(KEY_SPACE)?; - add_constant!(KEY_MINUS)?; - add_constant!(KEY_EQUALS)?; - add_constant!(KEY_LEFTBRACKET)?; - add_constant!(KEY_RIGHTBRACKET)?; - add_constant!(KEY_BACKSLASH)?; - add_constant!(KEY_NONUSHASH)?; - add_constant!(KEY_SEMICOLON)?; - add_constant!(KEY_APOSTROPHE)?; - add_constant!(KEY_GRAVE)?; - add_constant!(KEY_COMMA)?; - add_constant!(KEY_PERIOD)?; - add_constant!(KEY_SLASH)?; + add_constant!(KEY_DELETE)?; add_constant!(KEY_CAPSLOCK)?; add_constant!(KEY_F1)?; add_constant!(KEY_F2)?; @@ -126,7 +142,6 @@ pub fn add_module_constants(m: &PyModule) -> PyResult<()> { add_constant!(KEY_INSERT)?; add_constant!(KEY_HOME)?; add_constant!(KEY_PAGEUP)?; - add_constant!(KEY_DELETE)?; add_constant!(KEY_END)?; add_constant!(KEY_PAGEDOWN)?; add_constant!(KEY_RIGHT)?; @@ -150,7 +165,6 @@ pub fn add_module_constants(m: &PyModule) -> PyResult<()> { add_constant!(KEY_KP_9)?; add_constant!(KEY_KP_0)?; add_constant!(KEY_KP_PERIOD)?; - add_constant!(KEY_NONUSBACKSLASH)?; add_constant!(KEY_APPLICATION)?; add_constant!(KEY_POWER)?; add_constant!(KEY_KP_EQUALS)?; @@ -182,24 +196,6 @@ pub fn add_module_constants(m: &PyModule) -> PyResult<()> { add_constant!(KEY_VOLUMEDOWN)?; add_constant!(KEY_KP_COMMA)?; add_constant!(KEY_KP_EQUALSAS400)?; - add_constant!(KEY_INTERNATIONAL1)?; - add_constant!(KEY_INTERNATIONAL2)?; - add_constant!(KEY_INTERNATIONAL3)?; - add_constant!(KEY_INTERNATIONAL4)?; - add_constant!(KEY_INTERNATIONAL5)?; - add_constant!(KEY_INTERNATIONAL6)?; - add_constant!(KEY_INTERNATIONAL7)?; - add_constant!(KEY_INTERNATIONAL8)?; - add_constant!(KEY_INTERNATIONAL9)?; - add_constant!(KEY_LANG1)?; - add_constant!(KEY_LANG2)?; - add_constant!(KEY_LANG3)?; - add_constant!(KEY_LANG4)?; - add_constant!(KEY_LANG5)?; - add_constant!(KEY_LANG6)?; - add_constant!(KEY_LANG7)?; - add_constant!(KEY_LANG8)?; - add_constant!(KEY_LANG9)?; add_constant!(KEY_ALTERASE)?; add_constant!(KEY_SYSREQ)?; add_constant!(KEY_CANCEL)?; @@ -292,10 +288,7 @@ pub fn add_module_constants(m: &PyModule) -> PyResult<()> { add_constant!(KEY_KBDILLUMUP)?; add_constant!(KEY_EJECT)?; add_constant!(KEY_SLEEP)?; - add_constant!(KEY_APP1)?; - add_constant!(KEY_APP2)?; - add_constant!(KEY_AUDIOREWIND)?; - add_constant!(KEY_AUDIOFASTFORWARD)?; + add_constant!(KEY_NONE)?; add_constant!(KEY_SHIFT)?; add_constant!(KEY_CTRL)?; add_constant!(KEY_ALT)?; diff --git a/lib/wrapper/src/input_wrapper.rs b/lib/wrapper/src/input_wrapper.rs index abbd2678f8..fc6f2c08eb 100644 --- a/lib/wrapper/src/input_wrapper.rs +++ b/lib/wrapper/src/input_wrapper.rs @@ -30,23 +30,18 @@ fn mouse(visible: bool) { } #[pyfunction] -pub fn set_btnp(key: Key) { - instance().set_btnp(key); +pub fn setbtn(key: Key, state: bool) { + instance().setbtn(key, state); } #[pyfunction] -pub fn set_btnr(key: Key) { - instance().set_btnr(key); +pub fn setbtnv(key: Key, val: f64) { + instance().setbtnv(key, val); } #[pyfunction] -pub fn set_btnv(key: Key, val: f64) { - instance().set_btnv(key, val); -} - -#[pyfunction] -pub fn set_mouse_pos(x: f64, y: f64) { - instance().set_mouse_pos(x, y); +pub fn setmpos(x: f64, y: f64) { + instance().setmpos(x, y); } pub fn add_input_functions(m: &PyModule) -> PyResult<()> { @@ -55,9 +50,8 @@ pub fn add_input_functions(m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(btnr, m)?)?; m.add_function(wrap_pyfunction!(btnv, m)?)?; m.add_function(wrap_pyfunction!(mouse, m)?)?; - m.add_function(wrap_pyfunction!(set_btnp, m)?)?; - m.add_function(wrap_pyfunction!(set_btnr, m)?)?; - m.add_function(wrap_pyfunction!(set_btnv, m)?)?; - m.add_function(wrap_pyfunction!(set_mouse_pos, m)?)?; + m.add_function(wrap_pyfunction!(setbtn, m)?)?; + m.add_function(wrap_pyfunction!(setbtnv, m)?)?; + m.add_function(wrap_pyfunction!(setmpos, m)?)?; Ok(()) } diff --git a/pyxel/__init__.pyi b/pyxel/__init__.pyi index a382e025a7..49b2c96450 100644 --- a/pyxel/__init__.pyi +++ b/pyxel/__init__.pyi @@ -1,7 +1,7 @@ # flake8: noqa from typing import Callable, List, Optional, Tuple, Union -# constants +# Constants PYXEL_VERSION: str APP_FILE_EXTENSION: str @@ -50,8 +50,50 @@ EFFECT_SLIDE: int EFFECT_VIBRATO: int EFFECT_FADEOUT: int -# key -KEY_NONE: int +# Keys +KEY_BACKSPACE: int +KEY_TAB: int +KEY_RETURN: int +KEY_ESCAPE: int +KEY_SPACE: int +KEY_EXCLAIM: int +KEY_QUOTEDBL: int +KEY_HASH: int +KEY_DOLLAR: int +KEY_PERCENT: int +KEY_AMPERSAND: int +KEY_QUOTE: int +KEY_LEFTPAREN: int +KEY_RIGHTPAREN: int +KEY_ASTERISK: int +KEY_PLUS: int +KEY_COMMA: int +KEY_MINUS: int +KEY_PERIOD: int +KEY_SLASH: int +KEY_0: int +KEY_1: int +KEY_2: int +KEY_3: int +KEY_4: int +KEY_5: int +KEY_6: int +KEY_7: int +KEY_8: int +KEY_9: int +KEY_COLON: int +KEY_SEMICOLON: int +KEY_LESS: int +KEY_EQUALS: int +KEY_GREATER: int +KEY_QUESTION: int +KEY_AT: int +KEY_LEFTBRACKET: int +KEY_BACKSLASH: int +KEY_RIGHTBRACKET: int +KEY_CARET: int +KEY_UNDERSCORE: int +KEY_BACKQUOTE: int KEY_A: int KEY_B: int KEY_C: int @@ -78,33 +120,7 @@ KEY_W: int KEY_X: int KEY_Y: int KEY_Z: int -KEY_1: int -KEY_2: int -KEY_3: int -KEY_4: int -KEY_5: int -KEY_6: int -KEY_7: int -KEY_8: int -KEY_9: int -KEY_0: int -KEY_RETURN: int -KEY_ESCAPE: int -KEY_BACKSPACE: int -KEY_TAB: int -KEY_SPACE: int -KEY_MINUS: int -KEY_EQUALS: int -KEY_LEFTBRACKET: int -KEY_RIGHTBRACKET: int -KEY_BACKSLASH: int -KEY_NONUSHASH: int -KEY_SEMICOLON: int -KEY_APOSTROPHE: int -KEY_GRAVE: int -KEY_COMMA: int -KEY_PERIOD: int -KEY_SLASH: int +KEY_DELETE: int KEY_CAPSLOCK: int KEY_F1: int KEY_F2: int @@ -124,7 +140,6 @@ KEY_PAUSE: int KEY_INSERT: int KEY_HOME: int KEY_PAGEUP: int -KEY_DELETE: int KEY_END: int KEY_PAGEDOWN: int KEY_RIGHT: int @@ -148,7 +163,6 @@ KEY_KP_8: int KEY_KP_9: int KEY_KP_0: int KEY_KP_PERIOD: int -KEY_NONUSBACKSLASH: int KEY_APPLICATION: int KEY_POWER: int KEY_KP_EQUALS: int @@ -180,24 +194,6 @@ KEY_VOLUMEUP: int KEY_VOLUMEDOWN: int KEY_KP_COMMA: int KEY_KP_EQUALSAS400: int -KEY_INTERNATIONAL1: int -KEY_INTERNATIONAL2: int -KEY_INTERNATIONAL3: int -KEY_INTERNATIONAL4: int -KEY_INTERNATIONAL5: int -KEY_INTERNATIONAL6: int -KEY_INTERNATIONAL7: int -KEY_INTERNATIONAL8: int -KEY_INTERNATIONAL9: int -KEY_LANG1: int -KEY_LANG2: int -KEY_LANG3: int -KEY_LANG4: int -KEY_LANG5: int -KEY_LANG6: int -KEY_LANG7: int -KEY_LANG8: int -KEY_LANG9: int KEY_ALTERASE: int KEY_SYSREQ: int KEY_CANCEL: int @@ -290,10 +286,7 @@ KEY_KBDILLUMDOWN: int KEY_KBDILLUMUP: int KEY_EJECT: int KEY_SLEEP: int -KEY_APP1: int -KEY_APP2: int -KEY_AUDIOREWIND: int -KEY_AUDIOFASTFORWARD: int +KEY_NONE: int KEY_SHIFT: int KEY_CTRL: int KEY_ALT: int @@ -414,10 +407,9 @@ def btnp( def btnr(key: int) -> bool: ... def btnv(key: int) -> int: ... def mouse(visible: bool) -> None: ... -def set_btnp(key: int) -> None: ... -def set_btnr(key: int) -> None: ... -def set_btnv(key: int, val: float) -> None: ... -def set_mouse_pos(x: float, y: float) -> None: ... +def setbtn(key: int, state: bool) -> None: ... +def setbtnv(key: int, val: float) -> None: ... +def setmpos(x: float, y: float) -> None: ... # Graphics class Image: ...