Sleep

遇到了问题?请先进行搜索(中文和英文),然后在此提问

Moderators: tmplinshi, arcticir

Marcosa1020
Posts: 168
Joined: 23 Sep 2015, 19:15

Sleep

11 Dec 2015, 00:55

Hi,

下面有一段請各位前輩們指教,當我按下ButtonSTOP時,照理應該是過6秒後關閉backup。
但是實際上是直接關閉Backup.exe,沒有經過六秒,請問是哪裡寫錯呢?
謝謝。

ButtonSTOP:
WinActivate, ahk_id %k_ID%
Clipboard = STOP
SendInput STOP
S = "2015/10/10"
E = "2015/12/30"
If Now > CDate(S) And Now < CDate(E)
Sleep, 6000
Process, Close, Backup.exe
Return
garry
Posts: 3787
Joined: 22 Dec 2013, 12:50

Re: Sleep

11 Dec 2015, 03:00

about date

Code: Select all

S := 20151010
E := 20151231
stringmid,now,a_now,1,8
now:=now
If (Now >=S AND Now<=E)
  msgbox, %now%-date is between`n %s% and %e%
else
  msgbox,%now%-date is NOT between`n %s% and %e%
return
brackets { } missing

Code: Select all

;........
If Now > CDate(S) And Now < CDate(E)
 {
 Sleep, 6000
 Process, Close, Backup.exe
 }
Return
Marcosa1020
Posts: 168
Joined: 23 Sep 2015, 19:15

Re: Sleep

11 Dec 2015, 18:35

Hi Garry,

經測試下列寫法會變成按下STOP之後無法刪除Backup, 我是否漏了什麼? 請指教。

ButtonSTOP:
WinActivate, ahk_id %k_ID%
Clipboard = STOP
SendInput STOP
S = "2015/10/10"
E = "2015/12/30"
If Now > CDate(S) And Now < CDate(E)
{
Sleep, 6000
Process, Close, Backup.exe
}
Return
garry
Posts: 3787
Joined: 22 Dec 2013, 12:50

Re: Sleep

12 Dec 2015, 16:37

sorry, I didn't understand the script
tmplinshi or other users can help
Marcosa1020
Posts: 168
Joined: 23 Sep 2015, 19:15

Re: Sleep

12 Dec 2015, 20:32

Hi Garry,

Thank you so much.

Dears,
如果寫成以下這樣是可以在六秒後關閉程式,但如果加上HHSS就無法使用。

經測試後無法使用:
ButtonSTOP:
WinActivate, ahk_id %k_ID%
S := 20151008101010
E := 20151230101010
stringmid,now,a_now,1,8
now:=now
If (Now >=S AND Now<=E)
SendInput STOP
Else
SendInput {}
Sleep, 6000
Process, Close, Backup.exe
Return

經測試後可以使用:
ButtonSTOP:
WinActivate, ahk_id %k_ID%
S := 20151008
E := 20151213
stringmid,now,a_now,1,8
now:=now
If (Now >=S AND Now<=E)
SendInput STOP
Else
SendInput {}
Sleep, 6000
Process, Close, Backup.exe
Return
garry
Posts: 3787
Joined: 22 Dec 2013, 12:50

Re: Sleep

13 Dec 2015, 08:01

need brackets , if you have more then ONE line after if ... else
example :

Code: Select all

pr=calc.exe
run,%pr%
sleep,2000   ; maybe see ifwinexist / IfWinNotActive / WinActivate / WinWaitActive
Process, Exist, %pr%
if (ErrorLevel <> 0)
   {
   sleep,5000
   Process, Close, %pr%   ; - close calc.exe after 5 seconds
   }
else
   msgbox,%pr% not active
return
I think after 'else' in your example needs brackets

Code: Select all

;....  
Else
  {
  ;--   ( maybe use errorlevel if backup.exe exist / see above )
  ;SendInput {}   ;- (?)
  Sleep, 6000
  Process, Close, Backup.exe
  Return
  }
return  
User avatar
amnesiac
Posts: 186
Joined: 22 Nov 2013, 03:08
Location: Egret Island, China
Contact:

Re: Sleep

29 Jan 2016, 06:51

Marcosa1020 wrote: 如果寫成以下這樣是可以在六秒後關閉程式,但如果加上HHSS就無法使用。

經測試後無法使用:
ButtonSTOP:
WinActivate, ahk_id %k_ID%
S := 20151008101010
E := 20151230101010
stringmid,now,a_now,1,8
now:=now
If (Now >=S AND Now<=E)
SendInput STOP
Else
SendInput {}
Sleep, 6000
Process, Close, Backup.exe
Return
保持时间变量与SE的长度相同,这样就没问题了。可以先获取S的长度取时间变量,就行了。

Return to “请求帮助”

Who is online

Users browsing this forum: No registered users and 13 guests