diff options
-rw-r--r-- | src/win32/event.rs | 181 | ||||
-rw-r--r-- | src/win32/ffi.rs | 141 | ||||
-rw-r--r-- | src/win32/mod.rs | 19 |
3 files changed, 341 insertions, 0 deletions
diff --git a/src/win32/event.rs b/src/win32/event.rs new file mode 100644 index 0000000..83d775d --- /dev/null +++ b/src/win32/event.rs @@ -0,0 +1,181 @@ +use events; +use super::ffi; + +pub fn vkeycode_to_element(code: ffi::WPARAM) -> Option<events::Element> { + Some(match code { + //ffi::VK_LBUTTON => events::Lbutton, + //ffi::VK_RBUTTON => events::Rbutton, + //ffi::VK_CANCEL => events::Cancel, + //ffi::VK_MBUTTON => events::Mbutton, + //ffi::VK_XBUTTON1 => events::Xbutton1, + //ffi::VK_XBUTTON2 => events::Xbutton2, + ffi::VK_BACK => events::Back, + ffi::VK_TAB => events::Tab, + //ffi::VK_CLEAR => events::Clear, + ffi::VK_RETURN => events::Return, + //ffi::VK_SHIFT => events::Shift, + //ffi::VK_CONTROL => events::Control, + //ffi::VK_MENU => events::Menu, + ffi::VK_PAUSE => events::Pause, + ffi::VK_CAPITAL => events::Capital, + ffi::VK_KANA => events::Kana, + //ffi::VK_HANGUEL => events::Hanguel, + //ffi::VK_HANGUL => events::Hangul, + //ffi::VK_JUNJA => events::Junja, + //ffi::VK_FINAL => events::Final, + //ffi::VK_HANJA => events::Hanja, + ffi::VK_KANJI => events::Kanji, + ffi::VK_ESCAPE => events::Escape, + ffi::VK_CONVERT => events::Convert, + //ffi::VK_NONCONVERT => events::Nonconvert, + //ffi::VK_ACCEPT => events::Accept, + //ffi::VK_MODECHANGE => events::Modechange, + ffi::VK_SPACE => events::Space, + ffi::VK_PRIOR => events::Prior, + ffi::VK_NEXT => events::Next, + ffi::VK_END => events::End, + ffi::VK_HOME => events::Home, + ffi::VK_LEFT => events::Left, + ffi::VK_UP => events::Up, + ffi::VK_RIGHT => events::Right, + ffi::VK_DOWN => events::Down, + //ffi::VK_SELECT => events::Select, + //ffi::VK_PRINT => events::Print, + //ffi::VK_EXECUTE => events::Execute, + ffi::VK_SNAPSHOT => events::Snapshot, + ffi::VK_INSERT => events::Insert, + ffi::VK_DELETE => events::Delete, + //ffi::VK_HELP => events::Help, + 0x30 => events::Key0, + 0x31 => events::Key1, + 0x32 => events::Key2, + 0x33 => events::Key3, + 0x34 => events::Key4, + 0x35 => events::Key5, + 0x36 => events::Key6, + 0x37 => events::Key7, + 0x38 => events::Key8, + 0x39 => events::Key9, + 0x41 => events::A, + 0x42 => events::B, + 0x43 => events::C, + 0x44 => events::D, + 0x45 => events::E, + 0x46 => events::F, + 0x47 => events::G, + 0x48 => events::H, + 0x49 => events::I, + 0x4A => events::J, + 0x4B => events::K, + 0x4C => events::L, + 0x4D => events::M, + 0x4E => events::N, + 0x4F => events::O, + 0x50 => events::P, + 0x51 => events::Q, + 0x52 => events::R, + 0x53 => events::S, + 0x54 => events::T, + 0x55 => events::U, + 0x56 => events::V, + 0x57 => events::W, + 0x58 => events::X, + 0x59 => events::Y, + 0x5A => events::Z, + //ffi::VK_LWIN => events::Lwin, + //ffi::VK_RWIN => events::Rwin, + ffi::VK_APPS => events::Apps, + ffi::VK_SLEEP => events::Sleep, + ffi::VK_NUMPAD0 => events::Numpad0, + ffi::VK_NUMPAD1 => events::Numpad1, + ffi::VK_NUMPAD2 => events::Numpad2, + ffi::VK_NUMPAD3 => events::Numpad3, + ffi::VK_NUMPAD4 => events::Numpad4, + ffi::VK_NUMPAD5 => events::Numpad5, + ffi::VK_NUMPAD6 => events::Numpad6, + ffi::VK_NUMPAD7 => events::Numpad7, + ffi::VK_NUMPAD8 => events::Numpad8, + ffi::VK_NUMPAD9 => events::Numpad9, + ffi::VK_MULTIPLY => events::Multiply, + ffi::VK_ADD => events::Add, + //ffi::VK_SEPARATOR => events::Separator, + ffi::VK_SUBTRACT => events::Subtract, + ffi::VK_DECIMAL => events::Decimal, + ffi::VK_DIVIDE => events::Divide, + ffi::VK_F1 => events::F1, + ffi::VK_F2 => events::F2, + ffi::VK_F3 => events::F3, + ffi::VK_F4 => events::F4, + ffi::VK_F5 => events::F5, + ffi::VK_F6 => events::F6, + ffi::VK_F7 => events::F7, + ffi::VK_F8 => events::F8, + ffi::VK_F9 => events::F9, + ffi::VK_F10 => events::F10, + ffi::VK_F11 => events::F11, + ffi::VK_F12 => events::F12, + ffi::VK_F13 => events::F13, + ffi::VK_F14 => events::F14, + ffi::VK_F15 => events::F15, + /*ffi::VK_F16 => events::F16, + ffi::VK_F17 => events::F17, + ffi::VK_F18 => events::F18, + ffi::VK_F19 => events::F19, + ffi::VK_F20 => events::F20, + ffi::VK_F21 => events::F21, + ffi::VK_F22 => events::F22, + ffi::VK_F23 => events::F23, + ffi::VK_F24 => events::F24,*/ + ffi::VK_NUMLOCK => events::Numlock, + ffi::VK_SCROLL => events::Scroll, + /*ffi::VK_LSHIFT => events::Lshift, + ffi::VK_RSHIFT => events::Rshift, + ffi::VK_LCONTROL => events::Lcontrol, + ffi::VK_RCONTROL => events::Rcontrol, + ffi::VK_LMENU => events::Lmenu, + ffi::VK_RMENU => events::Rmenu, + ffi::VK_BROWSER_BACK => events::Browser_back, + ffi::VK_BROWSER_FORWARD => events::Browser_forward, + ffi::VK_BROWSER_REFRESH => events::Browser_refresh, + ffi::VK_BROWSER_STOP => events::Browser_stop, + ffi::VK_BROWSER_SEARCH => events::Browser_search, + ffi::VK_BROWSER_FAVORITES => events::Browser_favorites, + ffi::VK_BROWSER_HOME => events::Browser_home, + ffi::VK_VOLUME_MUTE => events::Volume_mute, + ffi::VK_VOLUME_DOWN => events::Volume_down, + ffi::VK_VOLUME_UP => events::Volume_up, + ffi::VK_MEDIA_NEXT_TRACK => events::Media_next_track, + ffi::VK_MEDIA_PREV_TRACK => events::Media_prev_track, + ffi::VK_MEDIA_STOP => events::Media_stop, + ffi::VK_MEDIA_PLAY_PAUSE => events::Media_play_pause, + ffi::VK_LAUNCH_MAIL => events::Launch_mail, + ffi::VK_LAUNCH_MEDIA_SELECT => events::Launch_media_select, + ffi::VK_LAUNCH_APP1 => events::Launch_app1, + ffi::VK_LAUNCH_APP2 => events::Launch_app2, + ffi::VK_OEM_1 => events::Oem_1, + ffi::VK_OEM_PLUS => events::Oem_plus, + ffi::VK_OEM_COMMA => events::Oem_comma, + ffi::VK_OEM_MINUS => events::Oem_minus, + ffi::VK_OEM_PERIOD => events::Oem_period, + ffi::VK_OEM_2 => events::Oem_2, + ffi::VK_OEM_3 => events::Oem_3, + ffi::VK_OEM_4 => events::Oem_4, + ffi::VK_OEM_5 => events::Oem_5, + ffi::VK_OEM_6 => events::Oem_6, + ffi::VK_OEM_7 => events::Oem_7, + ffi::VK_OEM_8 => events::Oem_8, + ffi::VK_OEM_102 => events::Oem_102, + ffi::VK_PROCESSKEY => events::Processkey, + ffi::VK_PACKET => events::Packet, + ffi::VK_ATTN => events::Attn, + ffi::VK_CRSEL => events::Crsel, + ffi::VK_EXSEL => events::Exsel, + ffi::VK_EREOF => events::Ereof, + ffi::VK_PLAY => events::Play, + ffi::VK_ZOOM => events::Zoom, + ffi::VK_NONAME => events::Noname, + ffi::VK_PA1 => events::Pa1, + ffi::VK_OEM_CLEAR => events::Oem_clear,*/ + _ => return None + }) +} diff --git a/src/win32/ffi.rs b/src/win32/ffi.rs index 937de67..f10ab0f 100644 --- a/src/win32/ffi.rs +++ b/src/win32/ffi.rs @@ -158,10 +158,151 @@ pub static SWP_NOSIZE: UINT = 0x0001; pub static SWP_NOZORDER: UINT = 0x0004; pub static SWP_SHOWWINDOW: UINT = 0x0040; +// http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx +pub static VK_LBUTTON: WPARAM = 0x01; +pub static VK_RBUTTON: WPARAM = 0x02; +pub static VK_CANCEL: WPARAM = 0x03; +pub static VK_MBUTTON: WPARAM = 0x04; +pub static VK_XBUTTON1: WPARAM = 0x05; +pub static VK_XBUTTON2: WPARAM = 0x06; +pub static VK_BACK: WPARAM = 0x08; +pub static VK_TAB: WPARAM = 0x09; +pub static VK_CLEAR: WPARAM = 0x0C; +pub static VK_RETURN: WPARAM = 0x0D; +pub static VK_SHIFT: WPARAM = 0x10; +pub static VK_CONTROL: WPARAM = 0x11; +pub static VK_MENU: WPARAM = 0x12; +pub static VK_PAUSE: WPARAM = 0x13; +pub static VK_CAPITAL: WPARAM = 0x14; +pub static VK_KANA: WPARAM = 0x15; +pub static VK_HANGUEL: WPARAM = 0x15; +pub static VK_HANGUL: WPARAM = 0x15; +pub static VK_JUNJA: WPARAM = 0x17; +pub static VK_FINAL: WPARAM = 0x18; +pub static VK_HANJA: WPARAM = 0x19; +pub static VK_KANJI: WPARAM = 0x19; +pub static VK_ESCAPE: WPARAM = 0x1B; +pub static VK_CONVERT: WPARAM = 0x1C; +pub static VK_NONCONVERT: WPARAM = 0x1D; +pub static VK_ACCEPT: WPARAM = 0x1E; +pub static VK_MODECHANGE: WPARAM = 0x1F; +pub static VK_SPACE: WPARAM = 0x20; +pub static VK_PRIOR: WPARAM = 0x21; +pub static VK_NEXT: WPARAM = 0x22; +pub static VK_END: WPARAM = 0x23; +pub static VK_HOME: WPARAM = 0x24; +pub static VK_LEFT: WPARAM = 0x25; +pub static VK_UP: WPARAM = 0x26; +pub static VK_RIGHT: WPARAM = 0x27; +pub static VK_DOWN: WPARAM = 0x28; +pub static VK_SELECT: WPARAM = 0x29; +pub static VK_PRINT: WPARAM = 0x2A; +pub static VK_EXECUTE: WPARAM = 0x2B; +pub static VK_SNAPSHOT: WPARAM = 0x2C; +pub static VK_INSERT: WPARAM = 0x2D; +pub static VK_DELETE: WPARAM = 0x2E; +pub static VK_HELP: WPARAM = 0x2F; +pub static VK_LWIN: WPARAM = 0x5B; +pub static VK_RWIN: WPARAM = 0x5C; +pub static VK_APPS: WPARAM = 0x5D; +pub static VK_SLEEP: WPARAM = 0x5F; +pub static VK_NUMPAD0: WPARAM = 0x60; +pub static VK_NUMPAD1: WPARAM = 0x61; +pub static VK_NUMPAD2: WPARAM = 0x62; +pub static VK_NUMPAD3: WPARAM = 0x63; +pub static VK_NUMPAD4: WPARAM = 0x64; +pub static VK_NUMPAD5: WPARAM = 0x65; +pub static VK_NUMPAD6: WPARAM = 0x66; +pub static VK_NUMPAD7: WPARAM = 0x67; +pub static VK_NUMPAD8: WPARAM = 0x68; +pub static VK_NUMPAD9: WPARAM = 0x69; +pub static VK_MULTIPLY: WPARAM = 0x6A; +pub static VK_ADD: WPARAM = 0x6B; +pub static VK_SEPARATOR: WPARAM = 0x6C; +pub static VK_SUBTRACT: WPARAM = 0x6D; +pub static VK_DECIMAL: WPARAM = 0x6E; +pub static VK_DIVIDE: WPARAM = 0x6F; +pub static VK_F1: WPARAM = 0x70; +pub static VK_F2: WPARAM = 0x71; +pub static VK_F3: WPARAM = 0x72; +pub static VK_F4: WPARAM = 0x73; +pub static VK_F5: WPARAM = 0x74; +pub static VK_F6: WPARAM = 0x75; +pub static VK_F7: WPARAM = 0x76; +pub static VK_F8: WPARAM = 0x77; +pub static VK_F9: WPARAM = 0x78; +pub static VK_F10: WPARAM = 0x79; +pub static VK_F11: WPARAM = 0x7A; +pub static VK_F12: WPARAM = 0x7B; +pub static VK_F13: WPARAM = 0x7C; +pub static VK_F14: WPARAM = 0x7D; +pub static VK_F15: WPARAM = 0x7E; +pub static VK_F16: WPARAM = 0x7F; +pub static VK_F17: WPARAM = 0x80; +pub static VK_F18: WPARAM = 0x81; +pub static VK_F19: WPARAM = 0x82; +pub static VK_F20: WPARAM = 0x83; +pub static VK_F21: WPARAM = 0x84; +pub static VK_F22: WPARAM = 0x85; +pub static VK_F23: WPARAM = 0x86; +pub static VK_F24: WPARAM = 0x87; +pub static VK_NUMLOCK: WPARAM = 0x90; +pub static VK_SCROLL: WPARAM = 0x91; +pub static VK_LSHIFT: WPARAM = 0xA0; +pub static VK_RSHIFT: WPARAM = 0xA1; +pub static VK_LCONTROL: WPARAM = 0xA2; +pub static VK_RCONTROL: WPARAM = 0xA3; +pub static VK_LMENU: WPARAM = 0xA4; +pub static VK_RMENU: WPARAM = 0xA5; +pub static VK_BROWSER_BACK: WPARAM = 0xA6; +pub static VK_BROWSER_FORWARD: WPARAM = 0xA7; +pub static VK_BROWSER_REFRESH: WPARAM = 0xA8; +pub static VK_BROWSER_STOP: WPARAM = 0xA9; +pub static VK_BROWSER_SEARCH: WPARAM = 0xAA; +pub static VK_BROWSER_FAVORITES: WPARAM = 0xAB; +pub static VK_BROWSER_HOME: WPARAM = 0xAC; +pub static VK_VOLUME_MUTE: WPARAM = 0xAD; +pub static VK_VOLUME_DOWN: WPARAM = 0xAE; +pub static VK_VOLUME_UP: WPARAM = 0xAF; +pub static VK_MEDIA_NEXT_TRACK: WPARAM = 0xB0; +pub static VK_MEDIA_PREV_TRACK: WPARAM = 0xB1; +pub static VK_MEDIA_STOP: WPARAM = 0xB2; +pub static VK_MEDIA_PLAY_PAUSE: WPARAM = 0xB3; +pub static VK_LAUNCH_MAIL: WPARAM = 0xB4; +pub static VK_LAUNCH_MEDIA_SELECT: WPARAM = 0xB5; +pub static VK_LAUNCH_APP1: WPARAM = 0xB6; +pub static VK_LAUNCH_APP2: WPARAM = 0xB7; +pub static VK_OEM_1: WPARAM = 0xBA; +pub static VK_OEM_PLUS: WPARAM = 0xBB; +pub static VK_OEM_COMMA: WPARAM = 0xBC; +pub static VK_OEM_MINUS: WPARAM = 0xBD; +pub static VK_OEM_PERIOD: WPARAM = 0xBE; +pub static VK_OEM_2: WPARAM = 0xBF; +pub static VK_OEM_3: WPARAM = 0xC0; +pub static VK_OEM_4: WPARAM = 0xDB; +pub static VK_OEM_5: WPARAM = 0xDC; +pub static VK_OEM_6: WPARAM = 0xDD; +pub static VK_OEM_7: WPARAM = 0xDE; +pub static VK_OEM_8: WPARAM = 0xDF; +pub static VK_OEM_102: WPARAM = 0xE2; +pub static VK_PROCESSKEY: WPARAM = 0xE5; +pub static VK_PACKET: WPARAM = 0xE7; +pub static VK_ATTN: WPARAM = 0xF6; +pub static VK_CRSEL: WPARAM = 0xF7; +pub static VK_EXSEL: WPARAM = 0xF8; +pub static VK_EREOF: WPARAM = 0xF9; +pub static VK_PLAY: WPARAM = 0xFA; +pub static VK_ZOOM: WPARAM = 0xFB; +pub static VK_NONAME: WPARAM = 0xFC; +pub static VK_PA1: WPARAM = 0xFD; +pub static VK_OEM_CLEAR: WPARAM = 0xFE; + // messages pub static WM_CHAR: UINT = 0x0102; pub static WM_COMMAND: UINT = 0x0111; pub static WM_DESTROY: UINT = 0x0002; +pub static WM_KEYDOWN: UINT = 0x0100; +pub static WM_KEYUP: UINT = 0x0101; pub static WM_MOUSEMOVE: UINT = 0x0200; pub static WM_PAINT: UINT = 0x000F; pub static WM_SIZE: UINT = 0x0005; diff --git a/src/win32/mod.rs b/src/win32/mod.rs index d8e2df2..95df9a4 100644 --- a/src/win32/mod.rs +++ b/src/win32/mod.rs @@ -4,6 +4,7 @@ use std::sync::atomics::AtomicBool; use std::ptr; use {Event, Hints}; +mod event; mod ffi; pub struct Window { @@ -340,6 +341,24 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, 0 }, + ffi::WM_KEYDOWN => { + use events::Pressed; + let element = event::vkeycode_to_element(wparam); + if element.is_some() { + send_event(window, Pressed(element.unwrap())); + } + 0 + }, + + ffi::WM_KEYUP => { + use events::Released; + let element = event::vkeycode_to_element(wparam); + if element.is_some() { + send_event(window, Released(element.unwrap())); + } + 0 + }, + _ => unsafe { ffi::DefWindowProcW(window, msg, wparam, lparam) } |