热键循环切换当前窗口为1/4、1/3、2/3屏幕大小

来源:互联网 发布:零售门店经营数据分析 编辑:程序博客网 时间:2024/04/30 08:25
;脚本功能是调整当前窗口的大小;sunwind ;2013年8月25日;需求是多爱英提出,我用了面向对象的ahk来实现的。;~ 按一下热键(win+z);~ 切换到  右下角1/4;~ 再按一下;~ 切换到  右下角 1/3;~ 再按一下 ;~ 切换到 右下角 2/3;~ 再按一下;~ 切换到  右下角 1/4SetTitleMatchMode, 3event_index:=-1#z::WinGetTitle, current_win, Aif (current_win!=old_win)event_index=-1if(event_index=-1){old_win:=current_winWinGetPos, X, Y, current_Width, current_Height, %current_win%  ;这里A应该改成目标窗口,只获取一次某窗口的大小  ;quarter := new quarter(current_Width,current_Height)  ;one_third:= new one_third(current_Width,current_Height)  ;two_third:= new two_third(current_Width,current_Height)  ;若针对窗体而不是屏幕则解除上面注释 并给窗体值  ;用SysGet, MonitorWorkArea,而未用A_ScreenWidth A_ScreenHeight 避免任务条的影响  SysGet, MonitorWorkArea, MonitorWorkArea,1  ;MsgBox, Monitor:`t`nLeft:`t%MonitorLeft% (%MonitorWorkAreaLeft% work)`nTop:`t%MonitorTop% (%MonitorWorkAreaTop% work)`nRight:`t%MonitorRight% (%MonitorWorkAreaRight% work)`nBottom:`t%MonitorBottom% (%MonitorWorkAreaBottom% work)  quarter := new quarter(MonitorWorkAreaRight ,MonitorWorkAreaBottom)  one_third:= new one_third(MonitorWorkAreaRight ,MonitorWorkAreaBottom)  two_third:= new two_third(MonitorWorkAreaRight ,MonitorWorkAreaBottom)}event_index+=1event_index:=Mod(event_index, 3)  ;3个状态循环,模3,模运算得出 0,1,2commandArray := ["quarter", "one_third", "two_third"]    runner:=commandArray[event_index+1] ;因为ahk的数组是从1开始的,对于索引为0时是空值,加一避免此问题  %runner%.zoom()  ;TrayTip, %current_win%缩放%runner%,% "w=" %runner%.getNewWidth()  ",h="  %runner%.getNewHeight() , 10,  NewWidth:=%runner%.getNewWidth()   NewHeight:=%runner%.getNewHeight()  WinMove, %current_win%,,MonitorWorkAreaRight-NewWidth,MonitorWorkAreaBottom-NewHeight,NewWidth,NewHeightReturnclass WinSize{   Width :=0   Height := 0   NewWidth:=0   NewHeight:=0   ;SetWidth(val){   ;   Width := val ; Can set the color using a function of the class   ;}   ;SetHeight(val){   ;   Height := val ; Can set the color using a function of the class   ;}   GetWidth(){      Return this.Width ;需要增加this   }   GetHeight(){      Return this.Height  ;需要增加this   }   GetNewWidth(){      Return this.NewWidth ;需要增加this   }   GetNewHeight(){      Return this.NewHeight  ;需要增加this   }__New(w="",h=""){if (w="")this.Width :=A_ScreenWidthElsethis.Width :=wif (h="")this.Height:=A_ScreenHeightElsethis.Height := h}}Class half extends WinSize{zoom(){this.NewWidth:=  this.Width//2  ;向下舍除 (//)this.NewHeight:=  this.Height}}Class quarter extends WinSize{zoom(){this.NewWidth:=  this.Width//2this.NewHeight:=  this.Height//2}}Class one_third extends WinSize{zoom(){this.NewWidth:= this.Width//3this.NewHeight:= this.Height}}Class two_third extends WinSize{zoom(){this.NewWidth:= this.Width*2//3this.NewHeight:= this.Height}}

原创粉丝点击