OSXvnc icon indicating copy to clipboard operation
OSXvnc copied to clipboard

Try to login Mac By TightVNC client fail(update)

Open pan2636119599 opened this issue 8 years ago • 12 comments

HI ! I download the newest source code and use it to control My Mac.It look likes all well.However,when I Try to used it to Login Mac(no any users login before),it did not work,then the screen can not update again. the Screen keeped the state before I type anything;

I want to know If I do something Wrong?

Thanks

Update: I find some artice wrote that CGEventPost not work preLogin,so I replace it with CGPostKeyboardEvent.Then all goes well.

I do not know why!

pan2636119599 avatar Sep 22 '15 12:09 pan2636119599

Please be more specific.

stweil avatar Sep 22 '15 12:09 stweil

@pan2636119599 : could you please send me your code improvement, either as a pull request on GitHub or here as a comment?

Thanks, Stefan

stweil avatar Oct 03 '15 07:10 stweil

@stweil I have created a pre-login agent which uses CGEventPost for simulating keyboard. FYI I am developing a remote control app similar to yours.

Keyboard

CGEventRef keyEvent = CGEventCreateKeyboardEvent( NULL, keyCode, down ) ;
CGEventPost( kCGHIDEventTap, keyEvent ) ;
CFRelease( keyEvent ) ;

Mouse

CGEventRef event = CGEventCreateMouseEvent(eventSource, eventType, mouseLocation, mouseButton );
CGEventPost(kCGHIDEventTap, event);
CFRelease(event);
Pre-login launch agent

Pre Login

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>my app label</string>
        <key>LimitLoadToSessionType</key>
        <string>LoginWindow</string>
        <key>RunAtLoad</key>
        <true/>
        <key>WorkingDirectory</key>
        <string>My app directory</string>
        <key>ProgramArguments</key>
        <array>
                <string>app absolute path</string>
                <string>service</string>
                <string>myservice</string>
        </array>
        <key>KeepAlive</key>
        <true/>
</dict>
</plist>

CGEventPost is not working, I get the following in the Console logs after login

Untrusted apps are not allowed to connect to Window Server before login. I have searched o chromium's remote control (which has keyboard and mouse simulation working) source code. They use CGEventPost for keyboard, but it works in login window.

https://cs.chromium.org/chromium/src/remoting/host/input_injector_mac.cc?rcl=0&l=42

They seem to use a sh file in privileged helper tools directory and use to to load the service, I tried putting our service in prieveleged helpers tool, but still the event handling fails.

The Deprecated API CGPostMouseEvent, CGPostKeyBoardEvent work without problem , but would really like to know how non deprecated keyboard API works in chromium

https://stackoverflow.com/questions/41429524/how-to-simulate-keyboard-and-mouse-events-using-cgeventpost-in-login-window-mac

This may help solve this bug in your remote host too.

sai-prasanna avatar Jan 04 '17 06:01 sai-prasanna

@stweil I solved this after long and arduous search, shall I give a pull request, it comes down to adding stuff to ldflags?

sai-prasanna avatar Jan 06 '17 08:01 sai-prasanna

Yes, please.

stweil avatar Jan 06 '17 10:01 stweil

Hey sorry @stweil , forgot about this thread. If I have the time I will give pull request, but you can fix it yourself.

Refer this answer

https://stackoverflow.com/questions/41429524/how-to-simulate-keyboard-and-mouse-events-using-cgeventpost-in-login-window-mac/41607430#41607430

sai-prasanna avatar May 23 '17 06:05 sai-prasanna

Appears that keyboard input doesn't work on a "default login screen" (before anybody has yet logged in) though mouse works fine there and everywhere else, and keyboard works everywhere else. I attempted some of the link options mentioned and didn't have much luck, though I didn't look too closely...

rdp avatar Dec 07 '17 21:12 rdp

For me, while running system server on macos 10.13.2, keyboard does not work too on login screen. So system server is actually unusable in my case.

GoodMirek avatar Jan 03 '18 20:01 GoodMirek

I have been able to get it work on Mojave following the stackoverflow article posted by sai-prasanna

romanprocopie avatar Jul 11 '19 15:07 romanprocopie

@romanprocopie do you have a git diff or anything? I could never get it to work...

rdp avatar Jul 11 '19 15:07 rdp

@rdp have a look in the PR, worked out the box tbh

romanprocopie avatar Jul 11 '19 15:07 romanprocopie

Thank you to all who participated in the discussion here.

I merged pull request #39, so hopefully this issue is fixed. Please test and report your results.

stweil avatar Jul 11 '19 19:07 stweil