Git Product home page Git Product logo

Comments (13)

pentamassiv avatar pentamassiv commented on June 12, 2024

Thank you for the report. You wrote "in some games" does that mean that in general it works?
Also Windows makes a difference between Key::Shift, Key::LShift and Key::RShift. All these are different keys. The game might expect one of the other keys.

from enigo.

FurryWolfX avatar FurryWolfX commented on June 12, 2024

Thank you for the report. You wrote "in some games" does that mean that in general it works? Also Windows makes a difference between Key::Shift, Key::LShift and Key::RShift. All these are different keys. The game might expect one of the other keys.

When I use the physical keyboard in the game, it all triggers the skills properly. But using enigo doesn't trigger it.
F1-F12 can't be triggered either.

from enigo.

pentamassiv avatar pentamassiv commented on June 12, 2024

Can you please open Notepad and then run this slightly changed example

use enigo::{Enigo, Key, KeyboardControllable};
use std::thread;
use std::time::Duration;

fn main() {
    thread::sleep(Duration::from_secs(2));
    let mut enigo = Enigo::new();

    // select all
    enigo.key_down(Key::LShift);
    println!("Press key");
    thread::sleep(Duration::from_secs(5));
    enigo.key_up(Key::LShift);
}

Please try to press a letter key on your physical keyboard during the 5 seconds the example sleeps. If the letter is capitalized, we know that the Shift key works in general. Then we know that there must be some special case with the game

from enigo.

FurryWolfX avatar FurryWolfX commented on June 12, 2024

Can you please open Notepad and then run this slightly changed example

use enigo::{Enigo, Key, KeyboardControllable};
use std::thread;
use std::time::Duration;

fn main() {
    thread::sleep(Duration::from_secs(2));
    let mut enigo = Enigo::new();

    // select all
    enigo.key_down(Key::LShift);
    println!("Press key");
    thread::sleep(Duration::from_secs(5));
    enigo.key_up(Key::LShift);
}

Please try to press a letter key on your physical keyboard during the 5 seconds the example sleeps. If the letter is capitalized, we know that the Shift key works in general. Then we know that there must be some special case with the game

It works fine in Notepad and other editors. But not in Guild Wars 2, I don't know why.

from enigo.

pentamassiv avatar pentamassiv commented on June 12, 2024

Okay, thank you. That helps already to narrow it down. I probably need some time for this to investigate the issue.

from enigo.

FurryWolfX avatar FurryWolfX commented on June 12, 2024

And in-game chatting also works, just not when binding skills.

from enigo.

pentamassiv avatar pentamassiv commented on June 12, 2024

Maybe the old API to simulate input will work. Could you please try this changed example:

use enigo::{Enigo, Key, KeyboardControllable};
use std::thread;
use std::time::Duration;
use windows::Win32::UI::Input::KeyboardAndMouse::{KEYBD_EVENT_FLAGS, KEYEVENTF_KEYUP, VK_LSHIFT};

fn main() {
    thread::sleep(Duration::from_secs(2));
    let mut enigo = Enigo::new();

    // Simulate a key press
    unsafe {
        windows::Win32::UI::Input::KeyboardAndMouse::keybd_event(
            VK_LSHIFT.0 as u8,
            0,
            KEYBD_EVENT_FLAGS::default(),
            0,
        )
    };
    thread::sleep(Duration::from_millis(20));

    // Press other key (Change this if you'd like)
    enigo.key_click(Key::Layout('a'));

    // Simulate a key release
    thread::sleep(Duration::from_millis(20));
    unsafe {
        windows::Win32::UI::Input::KeyboardAndMouse::keybd_event(
            VK_LSHIFT.0 as u8,
            0,
            KEYEVENTF_KEYUP,
            0,
        )
    };
}

I don't know which other keys you want to press in order to see if Key::LShift works. Feel free to change this part of the example:

   // Press other key (Change this if you'd like)
   enigo.key_click(Key::Layout('a'));

from enigo.

FurryWolfX avatar FurryWolfX commented on June 12, 2024

Maybe the old API to simulate input will work. Could you please try this changed example:

use enigo::{Enigo, Key, KeyboardControllable};
use std::thread;
use std::time::Duration;
use windows::Win32::UI::Input::KeyboardAndMouse::{KEYBD_EVENT_FLAGS, KEYEVENTF_KEYUP, VK_LSHIFT};

fn main() {
    thread::sleep(Duration::from_secs(2));
    let mut enigo = Enigo::new();

    // Simulate a key press
    unsafe {
        windows::Win32::UI::Input::KeyboardAndMouse::keybd_event(
            VK_LSHIFT.0 as u8,
            0,
            KEYBD_EVENT_FLAGS::default(),
            0,
        )
    };
    thread::sleep(Duration::from_millis(20));

    // Press other key (Change this if you'd like)
    enigo.key_click(Key::Layout('a'));

    // Simulate a key release
    thread::sleep(Duration::from_millis(20));
    unsafe {
        windows::Win32::UI::Input::KeyboardAndMouse::keybd_event(
            VK_LSHIFT.0 as u8,
            0,
            KEYEVENTF_KEYUP,
            0,
        )
    };
}

I don't know which other keys you want to press in order to see if Key::LShift works. Feel free to change this part of the example:

   // Press other key (Change this if you'd like)
   enigo.key_click(Key::Layout('a'));

This example also does not trigger any skills that are tied to special keys (Shift and F1-F12 etc...)

I tried to simulate it using Python's Keyboard module and it works fine.

from enigo.

pentamassiv avatar pentamassiv commented on June 12, 2024

Okay, thank you for trying it out. Back to the drawing board :/

from enigo.

pentamassiv avatar pentamassiv commented on June 12, 2024

The same issue occurs with the game "Star Citizen"

from enigo.

pentamassiv avatar pentamassiv commented on June 12, 2024

Apparently it is best to send both, the scan code and the virtual key, in order for all programs to register the key input properly (e.g something like this https://github.com/Narsil/rdev/pull/113/files). Maybe that would solve this issue as well

from enigo.

pentamassiv avatar pentamassiv commented on June 12, 2024

I created #280, which might address this issue. It would be great if you could test it to see if it fixes it.

from enigo.

Aunmag avatar Aunmag commented on June 12, 2024

Same issue with Ctrl F1

from enigo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.