Skip to content

Commit 87d1561

Browse files
committed
examples: wowjump fix window focus problem in win11
1 parent c6c0421 commit 87d1561

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

examples/wowjump/logout.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/lxn/win"
1111
)
1212

13-
//LogoutStatus logout status.
13+
// LogoutStatus logout status.
1414
type LogoutStatus int
1515

1616
const (
@@ -24,7 +24,7 @@ const (
2424
ENTERING
2525
)
2626

27-
//Logout control Wow window status.
27+
// Logout control Wow window status.
2828
type Logout struct {
2929
prevTime time.Time
3030
subTime time.Duration
@@ -33,7 +33,7 @@ type Logout struct {
3333
count int
3434
}
3535

36-
//Update should be invoke by period.
36+
// Update should be invoke by period.
3737
func (l *Logout) Update() {
3838
switch l.currentState {
3939
case NORMAL:
@@ -131,7 +131,7 @@ func (l *Logout) enter() {
131131
}
132132
}
133133

134-
//Reset should be invoke by reset status.
134+
// Reset should be invoke by reset status.
135135
func (l *Logout) Reset() {
136136
l.currentState = NORMAL
137137
l.subTime = 0
@@ -174,12 +174,12 @@ func (l *Logout) logout() bool {
174174
return true
175175
}
176176

177-
//IsValid check the windows is valid.
177+
// IsValid check the windows is valid.
178178
func (l *Logout) IsValid() bool {
179179
return win.IsWindowVisible(l.hwnd)
180180
}
181181

182-
//CheckWindow check the window if in the foreground and in focus.
182+
// CheckWindow check the window if in the foreground and in focus.
183183
func (l *Logout) CheckWindow() bool {
184184
// 检查窗口
185185
if !l.IsValid() {
@@ -197,18 +197,24 @@ func (l *Logout) CheckWindow() bool {
197197
return true
198198
}
199199

200-
//TryGetWindow try focus window.
200+
// TryGetWindow try focus window.
201201
func (l *Logout) TryGetWindow() bool {
202202
focus := win.GetForegroundWindow()
203203
if focus != l.hwnd {
204204
win.ShowWindow(l.hwnd, win.SW_NORMAL)
205-
randomSleep(11, 22)
205+
randomSleep(500, 1000)
206206
win.SetActiveWindow(l.hwnd)
207-
randomSleep(11, 22)
207+
randomSleep(500, 1000)
208208
win.BringWindowToTop(l.hwnd)
209-
randomSleep(11, 22)
209+
randomSleep(500, 1000)
210210
win.SetForegroundWindow(l.hwnd)
211-
randomSleep(11, 22)
211+
randomSleep(500, 1000)
212+
focus = win.GetForegroundWindow()
213+
if focus != l.hwnd {
214+
log.Println("当前窗口不是wow,小退过程中不要动游戏窗口", focus, l.hwnd)
215+
randomSleep(500, 1000)
216+
return l.TryGetWindow()
217+
}
212218
return false
213219
}
214220
return true

0 commit comments

Comments
 (0)