Output the device's screen resolution in the specific format of [width]x[height]
(without the brackets). For example, an output could be 1440x900
.
Here's an online tester that you can use to check your own screen resolution.
Output the device's screen resolution in the specific format of [width]x[height]
(without the brackets). For example, an output could be 1440x900
.
Here's an online tester that you can use to check your own screen resolution.
-1 thanks to @manatwork
xdotool getdisplaygeometry|tr \ x
There are two spaces after the \
Gets geometry, then uses tr
to replace spaces with x
tr␠\␠␠x
. (Used ␠ to mark spaces here just because HTML rendering collapses consecutive whitespaces.)
\$\endgroup\$
– manatwork
May 4 '17 at 8:31
console.log((k=screen).width+'x'+k.height)
from PIL.ImageGrab import*;print'%dx%d'%grab().size
Saved 2 bytes by executing in Python 2
Saved 1 byte by changing import
i.grab().size
instead of the string formatting? I don't think it has to be exactly in the WxH
format
\$\endgroup\$
– DJMcMayhem♦
May 3 '17 at 21:23
i.grab().size
prints out a tuple as (1920, 1080)
. Granite that would save me 8 bytes, I'd rather go for accuracy to OPs requirements
\$\endgroup\$
– Wondercricket
May 3 '17 at 21:26
@for /f "tokens=1,2delims=x " %%A in ('"wmic path Win32_VideoController get VideoModeDescription|findstr "l""') do @echo %%Ax%%B
Basically the same thing as SteveFest's answer, except I grab a slightly shorter chunk of Wim32_VideoController and then I use something vaguely resembling regex to get the one line that contains the data that I want.
I have no idea why the wmic
string needs to be inside of double quotes to work, and I can't believe that I can't shorten the string at all.
Ordinarily, wmic path Win32_VideoController get VideoModeDescription
will display something like this:
VideoModeDescription
3440 x 1440 x 4294967296 colors
I can use findstr
's super rudimentary attempt at regex to find the letter "l," which only matches the line with the word "colors." From there, that line is delimited on spaces and the letter "x." %%A
contains the first token and %%B
contains the second token. After that, I just display the values.
I can't golf....
@for /f %%# in ('"@wmic path Win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution /format:value"')do @set %%#>nul
@echo %CurrentHorizontalResolution%x%CurrentVerticalResolution%
#!racket/gui
(let-values([(x y)(get-display-size #t)])(printf"~ax~a"x y))
Just discovered the (discouraged) shorthand for #lang
. Saves a few bytes! Documentation for get-display-size
.
from win32api import*
u=GetSystemMetrics
print u(0),'x',u(1)
_=>{var s=System.Windows.Forms.Screen.PrimaryScreen.Bounds;return s.Width+"x"+s.Height;};
This whole answer was written based on http://php-gtk.eu/en/code-hints/grabbing-a-screenshot-with-gdk
<?list($W,$H)=Gdk::get_default_root_window()->get_size();echo$W,x,$H;
Basically, fetches the "root" window (entire screen) and gets it's size.
Another way (based on http://www.kksou.com/php-gtk2/sample-codes/get-the-size-of-display-screen.php):
<?$w=(new GtkWindow())->get_screen();echo$w->get_width(),x,$w->get_height();
Gets the screen where the window was created, displaying it's dimentions.
var s=screen;console.log(s.width+'x'+s.height)
I wanted to write it in the comment but I don't have reputation yet. Can someone explain to me why other solutions don't count bytes for console.log()
? If they were counted then this solution would be the shortest.
a=get(0,'ScreenS');fprintf('%dx%d',a(3:4))
Uses property shortening. Other than that, this is a nice showcase of the inflexibility of MATLAB indexing, requiring a temporary variable a
. fprintf
prints to stdout
by default.
Shameless port of this Java answer
(#(str(.width %1)"x"(.height %1))(.getScreenSize(java.awt.Toolkit/getDefaultToolkit)))
0 hw:displaysize? swap . "x" . .
Returns the device's screen resolution of the first display (0) in pixels in the required format.
Output:
1536x864
()=>{var b=System.Windows.Forms.Screen.PrimaryScreen.Bounds;return b.Width+"x"+b.Height;};
This actually is quite a similiar answer to that one, which already exists, however, I'd like to add a few things. This solution acutally needs a reference to System.Windows.Forms and one to System.Drawing. Those references are not normally added for a console application, so I'm not sure wether it's valid. Therefore I wrote a solution without references, however this has 580 287 Bytes:
using System;using System.Runtime.InteropServices;class P{static void Main()=>Console.Write(G().Item1+"x"+G().Item2);static(int,int)G()=>(GetSystemMetrics(0),GetSystemMetrics(1));[DllImport("User32.dll",ExactSpelling=true,CharSet=CharSet.Auto)]static extern int GetSystemMetrics(int n);}
Here's the solution with line breaks:
using System;
using System.Runtime.InteropServices;
class P
{
static void Main() => Console.Write(G().Item1 + "x" + G().Item2);
static (int, int) G() => (GetSystemMetrics(0), GetSystemMetrics(1));
[DllImport("User32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
static extern int GetSystemMetrics(int n);
}
This solution was created with the huge help of AdamSchiavone on Stackoverflow.
I also wrote a C# Interactive programm with 123 Bytes, which automatically adds the references, so it can be executed on every machine without problems and without having the reference problems:
#r "System.Windows.Forms"
#r "System.Drawing"
var b=System.Windows.Forms.Screen.PrimaryScreen.Bounds;b.Width+"x"+b.Height
This basically is the same as the first one, but it adds the reference automatically and as it is executed in the interactive, you don't need the return statement, you can simply leave away the semicolon.
;
on the end of your func.
\$\endgroup\$
– TheLethalCoder
May 4 '17 at 8:23
Console
application, they are for a Windows Forms
one. Either way they don't need adding into the byte count.
\$\endgroup\$
– TheLethalCoder
May 4 '17 at 8:24
internal static class Program
to just class P
, you could probably remove static
from the methods and use new P()
, you can change IntPtr
to int
I believe, Move the i()
out of the struct
probably, change the struct
to a class
and probably a couple of other things.
\$\endgroup\$
– TheLethalCoder
May 4 '17 at 12:52
Locally declared windows function and anonymous VBE immediate window function that takes no input and outputs to the VBE Immediate window.
Note: The below may be made into a 64-bit compatible function by the addition of PtrSafe
following Declare
Declare Function GetSystemMetrics Lib"user32.dll"(ByVal i&)As Long
?GetSystemMetrics(0)&"x"&GetSystemMetrics(1)
tr , x</*/*/*/fb0/v*
If the device has frame buffer you can query /sys/class/graphics/fb0/virtual_size
to get resolution.
Width and Height are delimited by ,
so tr translates to x
.
Path to the file is shortened by using * to the point there are no ambiguities.
'0x0'
\$\endgroup\$ – Adám May 2 '17 at 16:14