gpt4 book ai didi

Ruby:如何在 Windows 中获取屏幕分辨率

转载 作者:可可西里 更新时间:2023-11-01 13:37:01 24 4
gpt4 key购买 nike

我刚才看到一个帖子,但主要的答案是针对 Linux 的。目前,在 Windows 上使用 Ruby 获取屏幕分辨率(宽度/高度)的最简单方法是什么。

最佳答案

一种简单的方法是包装系统命令并在 Ruby 中执行它们:

@screen = `wmic desktopmonitor get screenheight, screenwidth`

您可以显示它们或将其输出保存在文件中。

为了实际解析它,我在 this post 中找到了 Windows cmd.exe 的帮助程序:

for /f %%i in ('wmic desktopmonitor get screenheight^,screenwidth /value ^| find "="') do set "%%f"
echo your screen is %screenwidth% * %screenheight% pixels

这样您就可以轻松地获取变量中的值并将它们存储在您的 Ruby 程序中。

虽然我找不到像 Linux 那样的简单 gem 来执行此操作。

关于Ruby:如何在 Windows 中获取屏幕分辨率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49710692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com