Przesyłaj rozdzielczość ekranu urządzenia w określonym formacie [width]x[height]
(bez nawiasów). Na przykład wyjście może być 1440x900
.
Oto tester online, którego można użyć do sprawdzenia własnej rozdzielczości ekranu.
'0x0'
Przesyłaj rozdzielczość ekranu urządzenia w określonym formacie [width]x[height]
(bez nawiasów). Na przykład wyjście może być 1440x900
.
Oto tester online, którego można użyć do sprawdzenia własnej rozdzielczości ekranu.
'0x0'
Odpowiedzi:
(_=screen)=>_.width+"x"+_.height
Wyjścia jako funkcja return
. Dodaj f=
na początku i wywołaj jak f()
. Używa inicjalizacji parametru do inicjalizacji parametru _
do screen
obiektu. Reszta jest oczywista.
f=(_=screen)=>_.width+"x"+_.height
console.log(f())
Uwaga: przekazanie argumentu do tej funkcji spowoduje jej niepowodzenie.
with(screen)alert(width+"x"+height)
Nigdy nie myślałem, że pewnego dnia skorzystam with
! Nie sądzę, że można to dalej pograć w golfa.
s=screen,s.width+"x"+s.height
(29 znaków) również działa.
alert
: with(screen)(width+'x'+height)
po prostu zwraca odpowiedni ciąg.
_=screen,_.width+"x"+_.height
29 bajtów
* westchnienie * TI-BASIC zajmuje dodatkowy bajt na każdą małą literę.
+2 dzięki @Timtech
-3 dzięki @Timtech
:If ΔX>.1
:Then
:Disp "96x64
:Else
:Disp "320x240
Działa to tylko dlatego, że TI-BASIC można uruchomić tylko na kalkulatorach o dwóch różnych rozdzielczościach ekranu: 96 na 64 i 320 na 240. Po prostu testuję, aby zobaczyć, który ekran mam, ustawiając Zoom na coś, co jest różne w zależności od rozdzielczości ekranu, a następnie wyświetlanie prawidłowej rozdzielczości.
Na razie zaznaczam to jako niekonkurujące, ponieważ jest mocno zakodowane.
ZDecimal
a następnie używając innego Xmax
porównania, przynajmniej jednego bajtu. Myślę też, że musisz użyć małych liter, x
które są dwoma bajtami (x2) zamiast jednobajtowego odpowiednika wielkich liter.
ZDecimal
), ponieważ domyślny zoom ( ZStandard
) jest taki sam na obu kalkulatorach. Naprawię wielkie litery.
ZStandard
, będzie ΔX
inaczej niż w kalkulatorach? Ponadto ZDecimal
jest tylko jeden bajt, więc jest to 31 bajtów.
_=>(s=screen).width+'x'+s.height
console.log((_=>(s=screen).width+'x'+s.height)())
_=>(s=screen).width+'x'+s.height
zapisuje bajt
/*/*/sy*r SPDisplaysDataType|awk '/so/{print$2$3$4}'
Uruchamia się system_profiler
, pobiera SPDisplaysDataType
informacje, szuka pierwszego so
w Resolution
i drukuje rozdzielczość ekranu. W przypadku wielu ekranów powoduje to wydrukowanie wszystkich rozdzielczości.
Wcześniejszy wariant niezgodny:
/*/*/sy*r SPDisplaysDataType|grep so|tr -d 'R :a-w'
2880x1800\n1920x1080@60Hz
(dwie linie). Nie wiem czy to to dyskwalifikuje ... czy?
@60Hz
jest wyraźnie określony.
|sed 1q
, zwiększając liczbę bajtów do 58 bajtów.
awk
i mając jeden dodatkowy bajt. :)
s=screen;alert(s.width+"x"+s.height)
SysGet,w,0
SysGet,h,1
Send,%w%x%h%
Zapisz to w pliku z rozszerzeniem .AHK i uruchom z wiersza polecenia
Send
zamiast MsgBox
?
Dzięki @Johan du Toit za uratowanie bajtu!
#import<windows.h>
#define G GetSystemMetrics
f(){printf("%dx%d",G(0),G(1));}
#define G GetSystemMetrics f(){printf("%dx%d",G(0),G(1));}
-7 dzięki Martinowi Enderowi
-5 (właściwie 12!) Od Leaky Nun , magia Regex jest poza mną.
To jest długie, ale nie dłuższe niż przerażające System.Windows.Forms.SystemInformation.PrimaryMonitorSize
rozwiązanie
(gwmi win32_videocontroller|% v*n)-replace" |x \d+\D+$"
najpierw my Get-WmiObject
( gwmi
), aby pobrać Win32_VideoController
obiekt, który zawiera element o nazwie VideoModeDescription
, który jest łańcuchem w formacie 1920 x 1080 x 4294967296 colors
, a następnie uruchamiam zamianę wyrażenia regularnego, aby uzyskać poprawny format.
PS H:\> (gwmi win32_videocontroller|% v*n)-replace" |x \d+\D+$"
1920x1080
(gwmi win32_videocontroller|% v*n)-replace" |x[^x]+$"
goli kilka bajtów, modyfikując regex.
SystemInformation[][[1,5,2,1,2,1,2,2,;;,2]]~Infix~x
Może to nie działać w zależności od podłączonych urządzeń (nie wiem). Powinno to zawsze działać (zakładając, że masz podłączony przynajmniej jeden ekran):
Infix[Last/@("FullScreenArea"/.SystemInformation["Devices","ScreenInformation"][[1]]),x]
SystemInformation[]
zwraca wyrażenie formularza
SystemInformationData[{
"Kernel" -> {__},
"FrontEnd" -> {__},
"Links" -> {__},
"Parallel" -> {__},
"Devices" -> {__},
"Network" -> {__},
}]
Jesteśmy zainteresowani "Devices"
, do których można uzyskać bezpośredni dostęp jako SystemInformation["Devices"]
lub jako SystemInformation[][[1,5,2]]
. Rezultatem będzie lista formularza
{
"ScreenInformation" -> {__},
"GraphicsDevices" -> {__},
"ControllerDevices" -> {__}
}
Chcemy "ScreenInformation"
, do którego można uzyskać dostęp tak SystemInformation["Devices","ScreenInformation"]
zwięźle lub bardziej zwięźle SystemInformation[][[1,5,2,1,2]]
. Wynik będzie miał formę
{
{
"ScreenArea" -> {__},
"FullScreenArea" -> {{0,w_},{0,h_}},
"BitDepth" -> _,
"Resolution" -> _
},
___
}
Długość listy będzie liczbą podłączonych ekranów. Pierwszy ekran jest, SystemInformation[][[1,5,2,1,2,1]]
a szerokość i wysokość można wyodrębnić, ponieważ SystemInformation[][[1,5,2,1,2,1,2,2,;;,2]]
Następnie wstawiamy tylko Infix
x
dla formatu wyjściowego.
String f(){java.awt.Dimension s=java.awt.Toolkit.getDefaultToolkit().getScreenSize();return s.width+"x"+s.height;}
Ta metoda nie będzie działać w bezobsługowej instalacji Java (jak w TIO), ponieważ używa bibliotek awt. Dzwonię pod maskągetScreenSize
uses the Java Native Interface to call out (typically into a C library) for the screen width and screen height.
-9 bajtów dzięki Olivierowi Grégoire'owi za przypomnienie, że mogę zwrócić ciąg zamiast go wydrukować.
...x...
, because void f(){System.out.print((java.awt.Toolkit.getDefaultToolkit().getScreenSize()+"").replaceAll("[^\\d,]",""));}
which outputs 1920,1200
is shorter..
x
instead of ,
by using some regex replacement, but it's five bytes more than your current answer: void f(){System.out.print((java.awt.Toolkit.getDefaultToolkit().getScreenSize()+"").replaceAll("[^\\d,]","").replace(",","x"));}
or void f(){System.out.print((java.awt.Toolkit.getDefaultToolkit().getScreenSize()+"").replaceAll(".*?(\\d+).*?(\\d+).*","$1x$2"));}
Ah well, what isn't heavy in Java.. ;p
_=>{var s=System.Windows.Forms.Screen.PrimaryScreen.Bounds;return s.Width+"x"+s.Height;};
-6 bytes thanks to @TheLethalCoder by reminding me OP didn't mention about printing, so returning a string is also fine. And an additional -6 bytes by changing it to a lambda.
Func<string>
: ()=>{var s=System.Windows.Forms.Screen.PrimaryScreen.Bounds;return s.Width+"x"+s.Height;};
. However, you have a return of void
but you are returning a string
so you need to add 2 bytes for that.
_=>{var s=System.Windows.Forms.Screen.PrimaryScreen.Bounds;return s.Width+"x"+s.Height;};
var s=System.Windows.Forms.Screen.AllScreens[0].Bounds;
would also be the same count but you could golf it with that idea in mind.
read -aa<<<`xrandr`
echo ${a[7]}x${a[9]::-1}
xrandr
belongs to the X server, on Ubuntu is provided by x11-xserver-utils package.
Sample run:
bash-4.3$ read -aa<<<`xrandr`;echo ${a[7]}x${a[9]::-1}
1920x1080
xrandr|grep -oP '\d+x\d+'|line
Thanks to:
Sample run:
bash-4.3$ xrandr|grep -oP '\d+x\d+'|line
1920x1080
xrandr|grep *
work?
grep
and sed
attempts to parse xrandr
's output (pastebin.com/uTVcjWCq) were longer.
xrandr|grep *|cut -d' ' -f1
? (using the matching line from your paste @TIO)
from ctypes import*
u=windll.user32.GetSystemMetrics;
print u(0),'x',u(1)
print u(0),'x',u(1)
is smaller and his example (link) allows it
To clarify, If it's equivalent to the output from What is my screen resolution, It's valid.
in that website, there is space between each part
' '⎕R'x'⍕⌽⊃⎕WG'DevCaps'
⎕WG'DevCaps'
Window Get Device Capabilities
⊃
pick the first property (height, width)
⌽
reverse
⍕
format as text
' '⎕R'x'
Replace spaces with "x"s
Ox`ØP(s×Çn)±d+"x"+ight
The compressed string represents with(screen)width+"x"+height
. Ox
evaluates this as JavaScript, and the result is implicitly printed.
(-4 chars due to @AppleShell 's help)
Yes. it compiles.
m[3];main(){SDL_Init(32);SDL_GetDesktopDisplayMode(0,m);printf("%dx%d",m[1],m[2]);}
Run with : gcc snippet.c -lSDL2 && ./a.out
m
global and omitting int
: m[3];main(){...
m+1
should be shorter than m[1]
right? or isn't that possible in C but only in C++? surely printf has some dereference token
Thanks @Jonathan-allan, @felipe-nardi-batista
from Tkinter import*
print'%sx%s'%Tk().maxsize()
For single display setups, this matches the output from the site. This gives entire resolution for multiple displays.
print'x'....
saves a byte
v=Tk().maxsize()
, print'%sx%s'%v
saves 9 bytes.
print'%sx%s'%Tk().maxsize()
saves another 4 >_<
xdpyinfo|grep dim|cut -d' ' -f7
From man page:
xdpyinfo - is a utility for displaying information about an X server.
@Floris @manatwork Thanks for saving a few bytes!
-d\
instead of -d' '
. Then when it comes to both grep
for a line and cut
a part of that line, usually is shorter with a single awk
call: xdpyinfo|awk '/dim/&&$0=$2'
.
dimensions
but I don't have xdpyinfo
on my system...
grep *
expands the asterisk to all files in the directory.
grep|cut
is awk
.
*0
. My xrandr output is *0 3360 x 1050 ( 889mm x 278mm ) *0
.
-f2
Btw, Can you check xrandr|awk '/\*/{print $2}'
?
just for completeness:
PRINT "256x192"
outputs 256x192
. The Spectrum has a fixed hardwired screen resolution.
void setup(){fullScreen();print(width+"x"+height);}
This outputs in this format: width height
. Also, the program creates a window that is the size of the screen you are using (because every Processing program creates a window by default) and this program just outputs the height and the width of this window/sketch.
WIDTHxHEIGHT
.
((import html-toolkit)
(htmlOnLoad #::((var S(index(getWindow)screen))
(print(+(index S width)"x"(index S height))))))
(Line breaks added for readability)
Finally, my html-toolkit module gets some use! Only works in the Try it Online link, will not work from command line.
A few bytes could be saved if 1024 x 768
could be valid output. We just use (+ .. "x" .. )
to avoid print
's implicit spacing.
2048x1080
for a true 4K screen that's actually 4096x2160
. Any idea why? Firefox 52.0 on FreeBSD 11.
window.screen
and getting the width
and height
attributes from it. I imagine if you opened up the Firefox console and typed in window.screen
you'll see the apparently incorrect 2048x1080
.
$ set `xrandr`;echo $6x$8
3360x1050
Tested on a CentOS 5 box with display redirected to a Cygwin machine with two monitors. Here the full xrandr
output is
$ xrandr
SZ: Pixels Physical Refresh
*0 3360 x 1050 ( 889mm x 278mm ) *0
Current rotation - normal
Current reflection - none
Rotations possible - normal
Reflections possible - none
puts `xrandr`.split[7..9].join[0..-2]
Alternate solution (52 bytes):
puts `xrandr`.match(/t (\d+) (x) (\d+),/)[1..3].join