简体   繁体   English

以编程方式在 macOS 上创建虚拟显示器

[英]Creating a virtual display on macOS, programmatically

I am looking for the ability to create a virtual display on macOS, preferably using Electron/Node.js or native macOS development if that's the only resort.我正在寻找在 macOS 上创建虚拟显示器的能力,如果这是唯一的手段,最好使用 Electron/Node.js 或本机 macOS 开发。

I would like to create a virtual display that functions just like a real one, can be re-arranged etc.我想创建一个虚拟显示器,其功能与真实显示器一样,可以重新排列等。

Basically, imagine what happens when you plug in an HDMI cable into your computer - exactly the same.基本上,想象一下当您将 HDMI 电缆插入计算机时会发生什么——完全一样。

I looked into:我调查了:

But couldn't find any useful information - it's mostly read-only.但找不到任何有用的信息 - 它主要是只读的。

I don't know of any library that would give you this off-the-shelf (and anyway StackOverflow is not for library recommendations).我不知道有任何图书馆可以为您提供现成的(而且 StackOverflow 不适合图书馆推荐)。

If you were to implement it yourself, you would need to implement a virtual display driver.如果您要自己实现它,则需要实现一个虚拟显示驱动程序。 To do this you will need to learn about IOKit, IODisplay, IOFramebuffer and (possibly) IOGraphicsLib.为此,您需要了解 IOKit、IODisplay、IOFramebuffer 和(可能)IOGraphicsLib。 It's a pretty complicated project and you'll need to know C++.这是一个相当复杂的项目,您需要了解 C++。

See IOKit in Apple's documentation to get an idea of what you're looking at.请参阅 Apple 文档中的IOKit以了解您正在查看的内容。

Depending on what you're trying to do, it may be worthwhile looking at how VNC works, in particular the Remote Frame Buffer protocol.根据您要执行的操作,可能值得了解 VNC 的工作原理,尤其是远程帧缓冲区协议。

There is undocumented API in CoreGraphics to create virtual displays. CoreGraphics 中有未记录的 API 用于创建虚拟显示。 It works as one can expect, from Objective-C, based on the API (dumped in https://github.com/w0lfschild/macOS_headers/tree/master/macOS/Frameworks/CoreGraphics/1348/ ).它可以从 Objective-C 开始,基于 API (转储在https://github.com/w0lfschild/Frameworks/macOS_Graphicstree/w0lfschild/macOS . At least in macOS 10.15, no idea about macOS 11. But, as mentioned, it is undocumented and will thus possibly change without warning or might cause the machine to crash if used incorrectly.至少在 macOS 10.15 中,不知道 macOS 11。但是,如前所述,它没有记录,因此可能会在没有警告的情况下更改,或者如果使用不当可能导致机器崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM