Post not yet marked as solved
Is there any way to send key/mouse events to unfocused windows? Currently my code looks like this:
let src = CGEventSource(stateID: CGEventSourceStateID.hidSystemState)
let key_d = CGEvent(keyboardEventSource: src, virtualKey: 0x12, keyDown: true) // key "1" press
let key_u = CGEvent(keyboardEventSource: src, virtualKey: 0x12, keyDown: false) // key "1" release
key_d?.postToPid( (Int32)(pid) )
key_u?.postToPid( (Int32)(pid) )
Unfortunately this is working just for application, which owns menu bar.
I was trying different methods, but none of them is working. I would love to send those events directly to app by selecting specific window ID instead of pid, but anything working with not-focused apps will be good.
I'm developing application for macOS which require screen recording. Each time when I will recompile code, I have to manually add exception for this application in Security & Privacy (Screen Recording tab). Is there a way, to allow it only once?
I was trying to acces it using this code:
if( !CGPreflightScreenCaptureAccess())
{
print("not granted!")
let result = CGRequestScreenCaptureAccess()
if(result == true)
{
print("Screen recording granted, thank you.")
}
else
{
print("Not granted! Bye-bye...")
exit(1)
}
}
but CGRequestScreenCaptureAccess does not wait for approval.
I was also trying to poll current status by calling CGPreflightScreenCaptureAccess in a loop, but it always returned false, even after manual approval.
When I run this application from terminal (which have pernament access to screen), everything is working fine. But this way, I cannot debug anything.
Post not yet marked as solved
Hey,
I'm trying to record video from simulator - saving output to regular file works fine. I noticed in help, that this should be possible to redirect it to url: recordVideo [--codec=<codec>] [--display=<display>] [--mask=<policy>] [--force] <file or url>. I was trying to use different types of url, i.e. udp://127.0.0.1:9999 or tcp://127.0.0.1:9999 etc, but nothing works, I always get following error: Couldn't create an asset writer for writing video frames: allocationErrorError starting video recorder: simctl.SimulatorError.allocation Error. An error was encountered processing the command (domain=simctl.SimulatorError, code=2): We could not allocate necessary AV objects to perform the recording.
I was also trying to redirect it to different process, but it seems like this method was abandoned for some reason: xcrun simctl io booted recordVideo - | nc 127.0.0.1 9999
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=22): Error: rendering to standard out is no longer supported. Invalid argument
Do you have any idea, why this was abandoned? Or how can I stream video from my simulator using socket?
I'm using CoreSimulator 776.4.