Merge pull request #397 from go-vgo/bitmap-pr

Fixed window10 get scale error #393
This commit is contained in:
Evans 2021-11-14 15:38:10 -05:00 committed by GitHub
commit 1f517156ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 8 deletions

View File

@ -305,8 +305,8 @@ func Mul(x int) int {
// GetScaleSize get the screen scale size
func GetScaleSize() (int, int) {
x, y := GetScreenSize()
s := Scale()
return x * s / 100, y * s / 100
f := ScaleF()
return int(float64(x) * f), int(float64(y) * f)
}
// 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
func FindWindow(str string) win.HWND {
hwnd := win.FindWindow(nil, syscall.StringToUTF16Ptr(str))
func FindWindow(name string) win.HWND {
hwnd := win.FindWindow(nil, syscall.StringToUTF16Ptr(name))
return hwnd
}
// GetHWND get foreground window hwnd
func GetHWND() win.HWND {
hwnd := win.GetForegroundWindow()
return hwnd
}
@ -50,6 +48,26 @@ func SetActiveWindow(hwnd win.HWND) win.HWND {
}
// SetFocus set window focus with hwnd
func SetFocus(hWnd win.HWND) win.HWND {
return win.SetFocus(hWnd)
func SetFocus(hwnd win.HWND) win.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(idx, dpi)
}