Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

%A_ScreenWidth%/%A_ScreenHeight% broken on Windows 8.1?


  • Please log in to reply
15 replies to this topic
Asata
  • Members
  • 2 posts
  • Last active: Dec 06 2013 07:00 AM
  • Joined: 05 Dec 2013

Using a script that grabs the screen width and height would generally grab their monitor's resolution but for some reason on Windows 8.1 something weird happens. It's like it doesn't count the taskbar or something. I don't even know.

 

Here's an example for Skyrim:

#SingleInstance Force
#Persistent

SetTimer Skyrim, 5000
Return

Skyrim:
   WinGet IDs, List, ahk_class Skyrim
   Loop %IDs%
   {
    Screen_X = %A_ScreenWidth%
    Screen_Y = %A_ScreenHeight%
      ID := IDs%A_Index%
      If ID not in %Old_IDs%
      {
         WinActivate ahk_id %ID%
             WinSet, Style, -0xC40000, A
    WinMove, A, , 0, 0, Screen_X, Screen_Y
    WinActivate, A
      }
      New_IDs .= ID ","
   }
   StringTrimRight Old_IDs, New_IDs, 1
   New_IDs =
Return

 

With a 1920x1080 monitor Screen_X and Screen_Y should register as such - they did on Vista Ultimate. Using the following works fine:

 

WinMove, A, , 0, 0, 1920, 1080

 

So, I think something wonky's going on. I wouldn't doubt there being problems with 8.1 though so I figure it best to start a topic about it. Maybe if someone could make a small script that would just print A_ScreenWidth and A_ScreenHeight to a pop up or txt file or something would be useful.



Edd
  • Members
  • 212 posts
  • Last active: Jan 06 2016 07:36 AM
  • Joined: 24 Dec 2011

 I have the same problem here, I use this to discover the issue:

SysGet, MonitorWorkArea, MonitorWorkArea, 1
ToolTip, This should be at bottom,, %MonitorWorkAreaBottom%
Pause

ESC::
ExitApp

How can I get A_ScreenWidth and A_ScreenHeight completely funcional?
 



RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006

Perhaps try some of the available sub-commands in "sysget"

 

 

 

SM_CXSCREEN, SM_CYSCREEN: Width and height of the screen of the primary display monitor, in pixels. These are the same as the built-in variables A_ScreenWidth and A_ScreenHeight

;	This will return the x,y cordinates for the top left and bottom right
;	corners of the desktop work area (if 2 monitors, the entire area)

DesktopScreenCoordinates(byref Xmin, byref Ymin, byref Xmax, byref Ymax)
{
	SysGet, Xmin, 76 	; XVirtualScreenleft  	; left side of virtual screen
	SysGet, Ymin, 77	; YVirtualScreenTop		; Top side of virtual screen

	SysGet, VirtualScreenWidth, 78
	SysGet, VirtualScreenHeight, 79

	Xmax := Xmin + VirtualScreenWidth
	Ymax := Ymin + VirtualScreenHeight
	return
} 


Edd
  • Members
  • 212 posts
  • Last active: Jan 06 2016 07:36 AM
  • Joined: 24 Dec 2011

It doesn't work for my needs, I need to get a Gui exactly on the same position (based on distance from bottom to top i mean something like "A_ScreenHeight-100") no matter on what screen resolution the script is open, I think "MonitorWorkAreaBottom" would be perfect for having a base from that value



RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006
screenHeight := VirtualScreenHeight - Ymin 
y := screenHeight - 100

There are also various other subcommands which allow you to get the resolution of the active or specific monitor.

 

Does this work?

SysGet, aScreenHeight, 1 

/*

SM_CXSCREEN, SM_CYSCREEN: Width and height of the screen of the primary display monitor, in pixels. These are the same as the built-in variables A_ScreenWidth and A_ScreenHeight. 

*/


Linear Spoon
  • Members
  • 842 posts
  • Last active: Sep 29 2015 03:56 AM
  • Joined: 29 Oct 2011

It works for me...perhaps the problem is somewhere else in the script or in another installed program?

 

8ViNfCf.jpg


Join us at the new forum - http://www.ahkscript.org/

 


Edd
  • Members
  • 212 posts
  • Last active: Jan 06 2016 07:36 AM
  • Joined: 24 Dec 2011

It works for me...perhaps the problem is somewhere else in the script or in another installed program?

 

8ViNfCf.jpg

 

It works for me...perhaps the problem is somewhere else in the script or in another installed program?

 

8ViNfCf.jpg

Yes, that works well, but that does not the problem, the problem is that when you use that value to have a gui positioned or tooltip somewhere when the script is opened on different OS, the gui or tooltip or whatever is on a very different position of the screen, I don't know if i explain well, but tried this too:

SysGet, MonitorWorkArea, MonitorWorkArea, 1
ToolTip, This should be at bottom,, %MonitorWorkAreaBottom%
Pause

ESC::
ExitApp

on different OS the tooltip is shown at the bottom, and on windows 8.1 the tooltip is displayed at the top, so what i need is to get a same position on every OS no matter the resolution of the screen, so the gui (for example) will be always shown at same position. (in example just above the taskbar)



Linear Spoon
  • Members
  • 842 posts
  • Last active: Sep 29 2015 03:56 AM
  • Joined: 29 Oct 2011

One issue is that your script lacks CoordMode, Tooltip, Screen

The other is that Windows 8.1 doesn't want to display a tooltip over the taskbar for some reason.

CoordMode, Tooltip, Screen
SysGet, MonitorWorkArea, MonitorWorkArea, 1
ToolTip, This should be at bottom,, MonitorWorkAreaBottom-25
ESC::ExitApp

But still, every command here is working as documented.


Join us at the new forum - http://www.ahkscript.org/

 


Edd
  • Members
  • 212 posts
  • Last active: Jan 06 2016 07:36 AM
  • Joined: 24 Dec 2011

One issue is that your script lacks CoordMode, Tooltip, Screen

The other is that Windows 8.1 doesn't want to display a tooltip over the taskbar for some reason.

CoordMode, Tooltip, Screen
SysGet, MonitorWorkArea, MonitorWorkArea, 1
ToolTip, This should be at bottom,, MonitorWorkAreaBottom-25
ESC::ExitApp

But still, every command here is working as documented.

The tooltip was an example to check the screen coordinates, but I don't want a tooltip, I want a gui there, anyways, you fix the MonitorWorkAreaBottom with "-25"  you shouldn't do that, you should leave it just like that and show above the taskbar, If you open your script on a different OS, in example windows 7, the tooltip will be more up as shown on windows 8.1,because on previous Windows versions don't need the "-25" to show the tooltip above taskbar, remember that I'm looking for a way to show the gui at the same position no matter the screen resolution or OS used



Linear Spoon
  • Members
  • 842 posts
  • Last active: Sep 29 2015 03:56 AM
  • Joined: 29 Oct 2011

Are you trying to create a gui that doesn't extend into the taskbar or offscreen? I'm not sure I understand what you want.


Join us at the new forum - http://www.ahkscript.org/

 


Edd
  • Members
  • 212 posts
  • Last active: Jan 06 2016 07:36 AM
  • Joined: 24 Dec 2011

Just a little above the taskbar, but always on that position no matter on what screen resolution, or OS that is used (for example, 3 cms above the taskbar, and every time the script is opened the gui will be at 3 cms above the taskbar on every computer), that's what I need



Linear Spoon
  • Members
  • 842 posts
  • Last active: Sep 29 2015 03:56 AM
  • Joined: 29 Oct 2011

Well the issue with that is, not all screens have the same spacing between pixels. Windows knows how many pixels your monitor has, but not it's physical size. You can try to use A_ScreenDPI, but it's not guaranteed to be the actual "dots/pixels per inch", though it's very close on my monitors.

SysGet, MonitorWorkArea, MonitorWorkArea, 1
yPos := MonitorWorkAreaBottom-cmToInches(3)*A_ScreenDPI
Gui, Add, Text,, The top of this window should be about 3cm up from the taskbar
Gui, Show, y%yPos% xCenter w350 h100

ESC::ExitApp

cmToInches(cm)
{
	return cm*0.3937
}

Join us at the new forum - http://www.ahkscript.org/

 


Edd
  • Members
  • 212 posts
  • Last active: Jan 06 2016 07:36 AM
  • Joined: 24 Dec 2011

 

Well the issue with that is, not all screens have the same spacing between pixels. Windows knows how many pixels your monitor has, but not it's physical size. You can try to use A_ScreenDPI, but it's not guaranteed to be the actual "dots/pixels per inch", though it's very close on my monitors.

SysGet, MonitorWorkArea, MonitorWorkArea, 1
yPos := MonitorWorkAreaBottom-cmToInches(3)*A_ScreenDPI
Gui, Add, Text,, The top of this window should be about 3cm up from the taskbar
Gui, Show, y%yPos% xCenter w350 h100

ESC::ExitApp

cmToInches(cm)
{
	return cm*0.3937
}

Thanks, that is close enough, anyways I feel very weird all relative to screen coordinates on windows 8.1



patrick the average
  • Members
  • 1 posts
  • Last active: Jun 12 2014 05:16 PM
  • Joined: 12 Jun 2014

Hi. I don't have any solutions, but I wanted to share my similar issue. I have been having trouble with A_ScreenWidth and A_ScreenHeight also. When I MsgBox'd it came out right, but Gui Show was doing something different. When I upgraded AHK(thinking it might fix my problem), the MsgBox %A_ScreenWidth%X %A_ScreenHeight% came up with different numbers(smaller), but it seemed to be the dimensions that were being used by Gui Show(only as if the screen area used was pinned to the bottom right). All I have really been attempting to do is center a picture as a 'loading' sign, but it kept ending up low and to the right. This is on windows 8.1. I think there is indeed a bug or some incompatibility. SysGet 0 and 1(SM_CXSCREEN, SM_CYSCREEN) are also incorrect. I am able to overcome this by hardcoding Gui, Show, W1920 H1080, but it's less than idea. 



girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010

I know it's probably not an ideal solution but if you place your gui in the center of the screen and allow your user to move it to a more compatible location you could have your script detect the gui's position and record that in permanent storage like an INI or TXT file that the script can read in the next time the gui needs to be shown and place the gui in the new position automatically. Granted that would not place it in exactly the same spot in EVERY OS or Video system but it would place it in the same space for each individual user of the script. And if the location is in fact stored in a file somewhere any other script routines could find that and us it as a base point for other gui objects you've scripted.


The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ‚óŹ
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif