Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSX ARM - KeyPress(Key.Right) jumps all the way to end of line #59

Open
cdhanna opened this issue Jun 24, 2024 · 2 comments
Open

OSX ARM - KeyPress(Key.Right) jumps all the way to end of line #59

cdhanna opened this issue Jun 24, 2024 · 2 comments

Comments

@cdhanna
Copy link
Contributor

cdhanna commented Jun 24, 2024

I have this code,

await Task.Delay(500);
var robot = new Robot();
robot.AutoDelay = 1000;
robot.KeyPress(Key.Right);
Console.Beep();

And if I run the code while my cursor is sitting in the middle of some text, then the cursor will jump all the way to the end of the line.

I would expect that the cursor would only move 1 space to the right. However, the actual behaviour is closer to me holding COMMAND and then pressing the right-arrow key. (that will jump to the end of text in osx).

I've tried manually doing a KeyUp(Key.Command) before the KeyPress(Key.Right), but that doesn't seem to make a difference.

I'd love to try and help solve this, but the call to the .so file seems opaque to me. How are those files generated?

@cdhanna
Copy link
Contributor Author

cdhanna commented Jun 24, 2024

Oh I see, there is a file, /Desktop.Robot/Source/osx_arm/main.mm and I'm assuming I can build this similar to the osx build.sh script

@cdhanna
Copy link
Contributor Author

cdhanna commented Jun 24, 2024

Oooh, okay I fixed it. I'll try and open a second PR in a bit. (I have a pending one that I need my local version for, and I don't want to do the gits right now)

But, in general, I added this function to the Source/osx_arm/main.mm file,

    void sendCommandDownWithoutHotkey(short input){
        CGKeyCode inputKeyCode = input;
        CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
        CGEventRef saveCommandDown = CGEventCreateKeyboardEvent(source, inputKeyCode, true);
        CGEventPost(kCGAnnotatedSessionEventTap, saveCommandDown);
        CFRelease(saveCommandDown);
        CFRelease(source);
    }

And then also this one,

    void sendCommandWithoutHotkey(short input){
        sendCommandDownWithoutHotkey(input);
        sendCommandUp(input);
    }

And then I changed the KeyPress implementation in the ARM Robot implementation to use that new sendCommandWithoutHotkey method. And now it works as expected.

Oh, and I re-ran make in the Source/osx_arm/ directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant