shell-ahk
Version:
`Lodash`/`jQuery` for `AHK`.
207 lines (156 loc) • 6.12 kB
text/coffeescript
# -check
import windowShell_endsWith from './endsWith'
import windowShell_noop from './noop'
class WindowShell
###* import('./windowShell').Constructor ###
constructor: (exe, title = '') ->
###* import('./windowShell').WindowShell['exe'] ###
= ''
if windowShell_endsWith exe, '.exe' then = exe
else = "#{exe}.exe"
###* import('./windowShell').WindowShell['title'] ###
= ''
if title then = title
###* import('./windowShell').WindowShell['getWindowIdString'] ###
getWindowIdString: ->
windowShell_id =
unless windowShell_id then return ''
return "ahk_id #{windowShell_id}"
###* import('./windowShell').WindowShell['blur'] ###
blur: ->
windowShell_idString =
unless windowShell_idString then return
# 实际上是聚焦任务栏
name = 'ahk_class Shell_TrayWnd'
windowShell_noop name
Native 'WinActivate, %name%'
return
###* import('./windowShell').WindowShell['close'] ###
close: ->
windowShell_idString =
unless windowShell_idString then return
Native 'WinClose, % windowShell_idString'
return
###* import('./windowShell').WindowShell['focus'] ###
focus: ->
windowShell_idString =
unless windowShell_idString then return
Native 'WinActivate, % windowShell_idString'
return
###* import('./windowShell').WindowShell['getBounds'] ###
getBounds: ->
[windowShell_x, windowShell_y, windowShell_w, windowShell_h] = [0, 0, 0, 0]
windowShell_idString =
unless windowShell_idString then return {
x: windowShell_x
y: windowShell_y
width: windowShell_w
height: windowShell_h
}
Native 'WinGetPos, windowShell_x, windowShell_y, windowShell_w, windowShell_h, % windowShell_idString'
return {
x: windowShell_x
y: windowShell_y
width: windowShell_w
height: windowShell_h
}
###* import('./windowShell').WindowShell['getProcessId'] ###
getProcessId: ->
windowShell_idString =
unless windowShell_idString then return 0
windowShell_pid = 0
Native 'WinGet, windowShell_pid, PID, % windowShell_idString'
return windowShell_pid
###* import('./windowShell').WindowShell['getTitle'] ###
getTitle: ->
windowShell_idString =
unless windowShell_idString then return ''
if then return
windowShell_title = ''
Native 'WinGetTitle, windowShell_title, % windowShell_idString'
return windowShell_title
###* import('./windowShell').WindowShell['getWindowId'] ###
getWindowId: ->
windowShell_id = 0
windowShell_selector = ''
windowShell_noop windowShell_selector
if then windowShell_selector = "#{@title} ahk_exe #{@exe}"
else windowShell_selector = "ahk_exe #{@exe}"
Native 'WinGet, windowShell_id, ID, % windowShell_selector'
return windowShell_id
###* import('./windowShell').WindowShell['hide'] ###
hide: ->
windowShell_idString =
unless windowShell_idString then return
Native 'WinHide, % windowShell_idString'
return
###* import('./windowShell').WindowShell['isActive'] ###
isActive: ->
windowShell_id =
unless windowShell_id then return false
windowShell_activeId = WinActive "ahk_id #{windowShell_id}"
return windowShell_activeId == windowShell_id
###* import('./windowShell').WindowShell['isExists'] ###
isExists: ->
windowShell_id =
return windowShell_id > 0
###* import('./windowShell').WindowShell['isFullScreen'] ###
isFullScreen: ->
windowShell_idString =
unless windowShell_idString then return false
{ x, y, width, height } =
return x == 0 and y == 0 and width == A_ScreenWidth and height == A_ScreenHeight
###* import('./windowShell').WindowShell['kill'] ###
kill: ->
windowShell_idString =
unless windowShell_idString then return
Native 'WinKill, % windowShell_idString'
return
###* import('./windowShell').WindowShell['maximize'] ###
maximize: ->
windowShell_idString =
unless windowShell_idString then return
Native 'WinMaximize, % windowShell_idString'
return
###* import('./windowShell').WindowShell['minimize'] ###
minimize: ->
windowShell_idString =
unless windowShell_idString then return
Native 'WinMinimize, % windowShell_idString'
return
###* import('./windowShell').WindowShell['restore'] ###
restore: ->
windowShell_idString =
unless windowShell_idString then return
Native 'WinRestore, % windowShell_idString'
return
###* import('./windowShell').WindowShell['setPriority'] ###
setPriority: (level) ->
windowShell_id =
unless windowShell_id then return
windowShell_noop level
Native 'Process, Priority, % this.exe, % level'
return
###* import('./windowShell').WindowShell['setStyle'] ###
setStyle: (style) ->
windowShell_idString =
unless windowShell_idString then return
windowShell_noop style
Native 'WinSet, Style, % style, % windowShell_idString'
return
###* import('./windowShell').WindowShell['show'] ###
show: ->
windowShell_idString =
unless windowShell_idString then return
Native 'WinShow, % windowShell_idString'
return
###* import('./windowShell').WindowShell['wait'] ###
wait: (callback) ->
windowShell_selector = ''
windowShell_noop windowShell_selector
if then windowShell_selector = "#{@title} ahk_exe #{@exe}"
else windowShell_selector = "ahk_exe #{@exe}"
Native 'WinWait, % windowShell_selector'
if callback then callback()
return
windowShell_noop WindowShell