Fixed window10 get scale error #393

This commit is contained in:
vcaesar 2021-11-14 16:33:30 -04:00
parent 6fd41b9a7c
commit c1e28220b5
3 changed files with 44 additions and 7 deletions

View File

@ -305,8 +305,8 @@ func Mul(x int) int {
// GetScaleSize get the screen scale size // GetScaleSize get the screen scale size
func GetScaleSize() (int, int) { func GetScaleSize() (int, int) {
x, y := GetScreenSize() x, y := GetScreenSize()
s := Scale() f := ScaleF()
return x * s / 100, y * s / 100 return int(float64(x) * f), int(float64(y) * f)
} }
// SetXDisplayName set XDisplay name (Linux) // SetXDisplayName set XDisplay name (Linux)

19
robotgo_mac.go Normal file
View File

@ -0,0 +1,19 @@
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//go:build !windows
// +build !windows
package robotgo
// ScaleF get the system scale val
func ScaleF() float64 {
return SysScale()
}

View File

@ -21,16 +21,14 @@ import (
) )
// FindWindow find window hwnd by name // FindWindow find window hwnd by name
func FindWindow(str string) win.HWND { func FindWindow(name string) win.HWND {
hwnd := win.FindWindow(nil, syscall.StringToUTF16Ptr(str)) hwnd := win.FindWindow(nil, syscall.StringToUTF16Ptr(name))
return hwnd return hwnd
} }
// GetHWND get foreground window hwnd // GetHWND get foreground window hwnd
func GetHWND() win.HWND { func GetHWND() win.HWND {
hwnd := win.GetForegroundWindow() hwnd := win.GetForegroundWindow()
return hwnd return hwnd
} }
@ -50,6 +48,26 @@ func SetActiveWindow(hwnd win.HWND) win.HWND {
} }
// SetFocus set window focus with hwnd // SetFocus set window focus with hwnd
func SetFocus(hWnd win.HWND) win.HWND { func SetFocus(hwnd win.HWND) win.HWND {
return win.SetFocus(hWnd) return win.SetFocus(hWnd)
} }
// ScaleF get the system scale val
func ScaleF() float64 {
return float64(GetMainDPI()) / 96.0
}
// GetMainDPI get the display dpi
func GetMainDPI() int {
return int(GetDPI(GetHWND()))
}
// GetDPI get the window dpi
func GetDPI(hwnd win.HWND) uint32 {
return win.GetDpiForWindow(hwnd)
}
// GetSysDPI get the system metrics dpi
func GetSysDPI(idx int32, dpi uint32) int32 {
return win.GetSystemMetricsForDpi(idex, dpi)
}