enigo icon indicating copy to clipboard operation
enigo copied to clipboard

panicked at 'cannot transmute_copy if U is larger than T'

Open NaokiM03 opened this issue 2 years ago • 1 comments

Describe the bug

On windows, functions that use fn keybd_event(flags: u32, vk: u16, scan: u16) internally cause panic when used in Rust 1.64.0 or later.

See also the following issue. https://github.com/rust-lang/rust/issues/100545

thread 'main' panicked at 'cannot transmute_copy if U is larger than T', /rustc/f6f9d5e73d5524b6281c10a5c89b7db35c330634\library\core\src\mem\mod.rs:1057:5
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/f6f9d5e73d5524b6281c10a5c89b7db35c330634/library\std\src\panicking.rs:584
   1: core::panicking::panic_fmt
             at /rustc/f6f9d5e73d5524b6281c10a5c89b7db35c330634/library\core\src\panicking.rs:142
   2: core::mem::transmute_copy<winapi::um::winuser::KEYBDINPUT,winapi::um::winuser::INPUT_u>
             at /rustc/f6f9d5e73d5524b6281c10a5c89b7db35c330634\library\core\src\mem\mod.rs:1057
   3: enigo::win::win_impl::keybd_event
             at .\src\win\win_impl.rs:36
   4: enigo::win::win_impl::impl$1::key_down
             at .\src\win\win_impl.rs:138
   5: key::main
             at .\examples\key.rs:9
   6: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/f6f9d5e73d5524b6281c10a5c89b7db35c330634\library\core\src\ops\function.rs:248
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\examples\key.exe` (exit code: 101)

To Reproduce

Use rustc 1.64.0-nightly and run cargo run --example key.

Expected behavior

Expects a input, but in fact panic occurs.

Environment (please complete the following information):

  • OS: Windows
  • Rust: rustc 1.64.0-nightly (f6f9d5e73 2022-08-04)
  • Library Version: enigo 0.0.14

NaokiM03 avatar Aug 30 '22 06:08 NaokiM03

Thanks, I just ran into the problem and your solution saved my time.

psi-cmd avatar Sep 06 '22 16:09 psi-cmd

My steps:

  1. Get the PR
git clone https://github.com/enigo-rs/enigo.git
gh pr checkout 122

  1. Update Cargo.toml
[dependencies]
enigo = {path = "path/to/enigo", version = "0.0.14"}

mrchantey avatar Oct 28 '22 00:10 mrchantey

This issue is closed because the pull request has been merged.

NaokiM03 avatar Jan 27 '23 00:01 NaokiM03

Please when will a new version be released on crates.io

NPCDW avatar Feb 28 '23 07:02 NPCDW

The new version was released :)

pentamassiv avatar Mar 25 '23 21:03 pentamassiv