AutoHotKey

autohotkey) 네 코드를 보여, 내가 당신에게서 배우고 싶어요

by 디케 posted Jan 08, 2012
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

 

 

 

; Loading Area
   #SingleInstance Ignore
   #HotkeyModifierTimeout -1
   #NoEnv
   #Hotstring EndChars -()[]{}:;'"./\,?!`n `t
   #Include irCode.txt
   ;#NoTrayIcon
   SetBatchLines 10
   SetKeyDelay ,-1, -1
  
   CoordMode,Mouse,Screen
   coordMode,tooltip,Screen
   DetectHiddenText, On
   SetTitleMatchMode 2
   setWinDelay 10
  
   Iniread, masterVolStep, keyBoard.ini, section1, masterVolStep
   Iniread, lineStatut, keyBoard.ini, section1, lineStatut
   Iniread, upTimeRecord,keyboard.ini,section1,upTimeRecord
   Iniread, tvStatut, keyBoard.ini, section1, tvStatut
  
   DllCall("LoadLibrary", Str,"uuirtdrv.dll")
   hndl:= DllCall("uuirtdrv.dll\UUIRTOpen")
   DllCall("uuirtdrv.dll\UUIRTSetUUIRTConfig", UInt,hndl, UInt32,0x00)
   interceptIrAddress := RegisterCallback("interceptIr")
   DllCall("uuirtdrv.dll\UUIRTSetReceiveCallback",UInt,hndl, Int, interceptIrAddress,Str,"void")
  
   GroupAdd, autoReplace,Windows Live Hotmail
   GroupAdd, autoReplace,ahk_class IMWindowClass
   GroupAdd, autoReplace,ahk_class gdkWindowToplevel
   GroupAdd, autoReplace,ahk_class TSwForm
   GroupAdd, tvControl,pcTvControl
   GroupAdd, tvControl,ahk_class AfxWnd42
   GroupAdd, tvControl,ahk_class Progman
  
   taskBarH:=28
   winTitleH:=30
   gridW:=A_screenWidth
   gridH:=A_screenHeight-taskBarH
   gridSpaceX:=A_screenWidth/16
   gridSpaceY:=gridH/16
   TPS:=0.05
   TVQ:=0.075
   second:=1000
   minute:=60000
   heure:=3600000
   cycleReveil:=82
   setTimer,tmrCheckForSleep,%minute%
   gosub createDesktopNote
return ;;
; HotKey
   #UseHook
   volume_up:: ;
      ifless,masterVolStep,17,EnvAdd,masterVolStep,1
      IniWrite, %masterVolstep%, keyBoard.ini, section1, masterVolStep
      gosub showVolBar
   return ;;
   volume_down:: ;
      ifGreater,masterVolStep,0,EnvSub,masterVolStep,1
      IniWrite, %masterVolstep%, keyBoard.ini, section1, masterVolStep
      gosub showVolBar
   return ;;
   volume_mute:: SoundSet, +1,Line, mute
   pgUp:: ;
      keyPress:=analyseKeyPress("PgDn")
      a:= keyPress=1 ? sendIr(lightRaise,4)
      a:= keyPress=2 ? sendIr(lightOn,1)
      a:= keyPress=4 ? sendIr(lightPreset,1)
      ;while GetKeyState("PgUp","P"){
         ;tooltip %a_tickCount%
      ;}
   return ;;
   pgDn:: ;
      keyPress:=analyseKeyPress("PgUp")
      a:= keyPress=1 ? sendIr(lightLower,4)
      a:= keyPress=2 ? sendIr(lightOff,1)
      a:= keyPress=4 ? sendIr(lightPreset,1)
   return ;;
   numlock:: ;
      keyPress:=analyseKeyPress()
      ifEqual,keyPress,1,{
         ifEqual,tvStatut,1,gosub,switchToHDMI2
         else gosub switchToHDMI1
      }
      ifEqual,keyPress,2,gosub,switchToHDMI3
      ifEqual,keyPress,3,gosub,turnOffTv
   return ;;
   ESC:: ;
      keyPress:=analyseKeyPress("",0)
      ifEqual,keyPress,1,send,{%A_thishotKey%}
      ifEqual,keyPress,3,gosub,toggleDesktop
   return ;;
   capslock:: ;
      WinGetActiveTitle, winTitle
      username:=
      #Include pssWrd.txt
      ifNotEqual,userName,,send,%userName%{tab}
      send %pssWrd%{Enter}
   return ;;
   ~lButton:: ;
      If WinActive("ahk_class Progman"){
         MouseGetPos, mouseX, mouseY,,controlName
         ifEqual,controlName,Edit1,ControlClick,x%mouseX% y%MouseY%, ahk_class Progman,,,,na
         ifEqual,controlName,Edit1,ControlFocus, Edit1, ahk_class Progman
      }
   return ;;
   mButton:: ;
      MouseGetPos,,,winTitle
      WinActivate ,%WinTitle%
      keyPress:=analyseKeyPress()
      if(keyPress=1){
         winset,AlwaysOnTop,toggle,ahk_id %winID%
      }else if(keyPress=2){
         DllCall("TileWindows",Int,0,UInt,0,UInt,0,Int,0,Int,0)
      }else if(keyPress=3){
         MouseGetPos,mouseX,mouseY,winId
         WinGetPos,winX,winY,winW,winH,ahk_id %winID%
         Loop{
            GetKeyState,btnState,%A_thishotkey%,P
            ifEqual,btnState,U,Break
            MouseGetPos,mouseX2,mouseY2
            newWinX :=(round((winX + mouseX2 - mouseX)/gridSpaceX)*gridSpaceX)
            newWinY :=(round((winY + mouseY2 - mouseY)/gridSpaceY)*gridSpaceY)
            ;ifGreater,newWinX,(%gridW%-%gridSpaceX%),setEnv,newWinx,(%gridW%-%gridSpaceX%)
            if(NewWinX>gridW-gridSpaceX)
               newWinX:=gridW-gridSpaceX
            if(NewWinX+winW<gridSpaceX)
               newWinX:=-winW+gridSpaceX
            if(NewWinY>gridH-gridSpaceY)
               newWinY:=gridH-gridSpaceY
            if(NewWinY+winH<gridSpaceY)
               newWinY:=-winH+gridSpaceY
            WinMove,ahk_id %winID%,,%newWinX%,%newWinY%
         }
      }
   return ;;
   rButton:: ;
      MouseGetPos,,,winTitle
      WinActivate ,%WinTitle%
      keyPress:=analyseKeyPress()
      if(keyPress=1){
         click right
      }else if(keyPress=2){
         WinMinimize, A
      }else if(keyPress=3){
         MouseGetPos,mouseX,mouseY,winID
         WinGetPos,winX,winY,winW,winH,ahk_id %winID%
         Loop{
            GetKeyState,btnState,%A_ThisHotKey%,P
            ifEqual,btnState,U,Break
            MouseGetPos,mouseX2,mouseY2
            newWinW :=(round((winW + mouseX2 - mouseX)/gridSpaceX)*gridSpaceX)
            newWinH :=(round((winH + mouseY2 - mouseY)/gridSpaceY)*gridSpaceY)
            WinMove,ahk_id %winID%,,,,%newWinW%,%newWinH%
         }
      }
   return ;;
   +esc:: ; Eject Drive
      Drive, Eject,F:
      ifless,A_TimeSinceThisHotkey,1000,Drive, Eject,f:, 1
   return ;;
   !F5:: ; nes
      run D:\Jeux\Nintendo\Nes\Nestopia139bin\nestopia.exe,D:\Jeux\Nintendo\Nes\Nestopia139bin
   return ;;
   !F6:: ; snes
      run D:\Jeux\Nintendo\Snes\zsnesw151\zsnesw,D:\Jeux\Nintendo\Snes\zsnesw151\
   return ;;
   !F7:: ; n64
      run C:\Program Files\Project64 1.6\Project64.exe,C:\Program Files\Project64 1.6\
   return ;;
   !F8:: ; sony
      run D:\Jeux\Sony\PlayStation 1\PSX\pSX_1_13\psxfin.exe,D:\Jeux\Sony\PlayStation 1\PSX\pSX_1_13\
   return ;;
   !F9:: ; mame
      run D:\Jeux\Mame\Mame32.exe,E:\Jeux\Mame\
   return ;;
   !a::run d:\Audio
   !b::run d:\backup
   !c:: ; calc
      gui4w:=gridSpaceX*4
      ifWinNotExist simpleCalc
      {
         file = $temp$.ahk
         Gui 4: Add, ComboBox, X0 Y0 R6 w%gui4w% vExpr simple
         Gui 4: Add, Button, Default, OK
         Gui 4: +toolwindow +alwaysOnTop
         Gui 4: Show, w%gui4w% H100,simpleCalc
      }
      return
      4ButtonOK:
         GuiControlGet Expr,,Expr
         ifEqual,expr,"",Return
         FileDelete %file%
         FileAppend #NoTrayIcon`nFileDelete %file%`nFileAppend `% %Expr%`, %file%, %file%
         RunWait %A_AhkPath% %file%
         FileRead Result, %file%
         FileDelete %file%
         ifEqual,result,"",Return
         SetFormat, Float, 0.2
         ;Expr:=Expr+0
         result:=result+0
         GuiControl,,Expr,%Expr%
         GuiControl,,Expr,%Result%
         N += 2
         GuiControl Choose,Expr,%N%
         send {right}
      Return
      4GuiEscape:
      4GuiClose:
         n:=0
         Gui 4: destroy
      return
   return ;;
   !d::run D:\Backup\Downloads
   !g:: ; Google
      run C:\Documents and Settings\%A_userName%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
   return ;;
   !h:: ; AutoHotKey
      edit
      winwait %A_ScriptName%
      send !0
   return ;;
   !j::run C:\Program Files\AutoHotkey\AutoHotkey.chm
   !i::gosub learnIr
   !l::Run d:\BackUp\_Logiciel
   !m:: ; Media player Classic
      run C:\Program Files\K-Lite Codec Pack\Media Player Classic\mpc-hc.exe
   return ;;
   !p::send @hotmail.com
   !q:: ; AHK relative
      AutoTrim Off
      Clipboard=
      send ^c
      ClipWait 1
      StringReplace, Hotstring, Clipboard, ``, ````, All
      StringReplace, Hotstring, Hotstring, `r`n, ``r, All
      StringReplace, Hotstring, Hotstring, `n, ``r, All
      StringReplace, Hotstring, Hotstring, %A_Tab%, ``t, All
      StringReplace, Hotstring, Hotstring, `;, ```;, All
      StringRight, lastChar, hotString, 1
      if(lastchar=" ")
         StringTrimRight, hotstring, hotstring, 1
        
      InputBox, autoReplaceCorrection ,,%HotString%,,,,,,,,%HotString%
      if(hotString<>""){
         if(autoReplaceCorrection="")
            autoReplaceCorrection:=HotString
         ifEqual,ErrorLevel,0,FileAppend, `n`:*:%hotString%::%autoReplaceCorrection%, autoReplace.txt
         ifEqual,ErrorLevel,0,gosub reloadAhk
      }
   return    ;;
   !t:: ; TV
      run C:\Program Files\ATI Multimedia\main\atimmc
      winwait ahk_class #32770
      winClose ahk_class #32770
      WinWaitClose ahk_class #32770
      send {F2}
      send +2
      SoundSet, 0,Line, mute
      ControlClick, Afx:400000:3:10011:0:03, ahk_class AfxWnd42
      setTimer, checkTvSoft,100
   return
   checkTvsoft:
      IfWinNotExist, ahk_class AfxWnd42,setTimer, checkTvSoft,off
      IfWinNotExist, ahk_class AfxWnd42,SoundSet, 1,Line, mute
   return ;;
   !v::run E:\VideoClip
   !w:: ;
      run C:\Program Files\Winamp\winamp.exe
      setTimer,checkWinampVideo,500
   return
   checkWinampVideo:
      winampVideoVisible:=0
      ifWinExist, ahk_class Winamp Video
         winampVideoVisible:=1
      if(WinampVideoVisible<>lastWinampVideoVisible){
         WinGetText, winText, ahk_class MediaPlayerClassicW
         if (winampVideoVisible=1){
            IfInString, winText, Paused
               return
            else
               controlSend,,{space},ahk_class MediaPlayerClassicW
               sleep 100
               WinMinimize, ahk_class MediaPlayerClassicW
         }else{
            IfInString, winText, Paused
            {
               WinRestore,ahk_class MediaPlayerClassicW
               controlSend,,{F11},ahk_class MediaPlayerClassicW
               controlSend,,{space},ahk_class MediaPlayerClassicW
              
            }
         }
      }
      lastWinampVideoVisible:=WinampVideoVisible
   return ;;
   ^!bs:: ; resolution
      ifWinExist, ahk_class AfxWnd42
      {
         msgbox Shut Down TV Soft First
         return
      }
      if(A_screenWidth<1280){
         ChangeDisplaySettings(1280,768)
      }else if(A_screenWidth>=1280){         ;<---  To Activate 1920 Reso Remove "="
         ChangeDisplaySettings(848,480)  
      }else{
         ChangeDisplaySettings(1920,1080)
      }
      gosub reloadAhk
   return ;;
   ^!c:: ; VNC Carole
      run Carole.vnc
      FileCreateShortcut, \\Carole\Desktop, %A_Desktop%\Carole.lnk
   return ;;
   ^!h::gosub reloadAhk
   ^!j::suspend
   ^!s:: ; VNC SEG
      run SEG.vnc
      FileCreateShortcut, \\SEG\Desktop, %A_Desktop%\SEG.lnk
   return ;;
   +^!p:: ; PssWrd
      WinGetTitle, winTitle,A
      InputBox,userName,%winTitle%,UserName
      InputBox,pssWrd,%winTitle%,Password, HIDE
      if(errorLevel=0){
         pssWrd:=encode(psswrd)
         fileAppend,`nif(winTitle=`"%winTitle%`"){,pssWrd.txt
         fileAppend,`n   pssWrd:=decode(`"%pssWrd%`"),pssWrd.txt
         fileAppend,`n   userName=%username%,pssWrd.txt
         fileAppend,`n},pssWrd.txt
         sleep 200
         gosub reloadAhk
      }
   return
   encode(stringToEncode){
      Length := StrLen(stringToEncode)
      loop, %length%{
         StringMid, char, stringToEncode, %a_index%,1,
         temp:=Asc(char)
         if (temp<100)
            temp=0%temp%
         stringEncode=%stringEncode%%temp%
      }
      return %stringEncode%
   } ;;
   ::ahk::AutoHotKey
   :*:cc:: ;
      ;send creditCard number
      ;tooltip expiration
      ;SetTimer, RemoveToolTip, -5000
   return
   RemoveToolTip:
      ToolTip
   return ;;
return ;;
; ifWin HotKey
   #ifWinActive simpleCalc
      :?*:pi::3.141592653589793
      :?*:s::sqrt(){left}
      :?*:e::`*`*2
   return ;;
   #ifWinActive ahk_group autoReplace
      #Include autoReplace.txt
   return ;;
   #ifWinExist menuSamsung
      up::sendIr(tvUp,1)
      right:: ;
         sendIr(tvRight,1)
         Ifless,menuCmp,3,envAdd,menuCmp,1
      return ;;
      down::sendIr(tvDown,1)
      left:: ;
         sendIr(tvLeft,1)
         ifEqual,menuCmp,1,gui 5:Destroy
         Ifless,menuCmp,3,envSub,menuCmp,1
      return ;;
      enter:: ;
         sendIr(tvEnter,1)
         setEnv,menuCmp,2
      return ;;
      bs:: ;
         a:= menuCmp=1 ? sendIr(tvMenu,1):sendIr(tvReturn,1)
         ifEqual,menuCmp,1,gui 5:Destroy
         ifNotEqual,menuCmp,1,setEnv,menuCmp,2
      return ;;
   return ;;

   #ifWinActive ahk_group tvControl
      numpad1::sendIr(sat1)
      numpad2::sendIr(sat2)
      numpad3::sendIr(sat3)
      numpad4::sendIr(sat4)
      numpad5::sendIr(sat5)
      numpad6::sendIr(sat6)
      numpad7::sendIr(sat7)
      numpad8::sendIr(sat8)
      numpad9::sendIr(sat9)
      numpad0::sendIr(sat0)
      numpadDot::sendIr(satRecall)
      numpadDiv:: ;
         keyPress:=analyseKeyPress()
         a:= keyPress=1 ? sendIr(satSkipBack)
         a:= keyPress=2 ? sendIr(satBack)
      return ;;
      numpadMult:: ;
         keyPress:=analyseKeyPress()
         a:= keyPress=1 ? sendIr(satPause)
         a:= keyPress=2 ? sendIr(satPlay)
      return ;;
      numpadSub:: ;
         keyPress:=analyseKeyPress()
         a:= keyPress=1 ? sendIr(satSkipFwd)
         a:= keyPress=2 ? sendIr(satFwd)
      return ;;
      g::sendIr(satGuide)
      i::sendIr(satInfo)
      l::sendIr(satLive)
      m::sendIr(satMenu)
      p::sendIr(satPvr)
      r::sendIr(satRecord)
      s::sendIr(satStop)
      t:: ;
         sendIr(tvMenu)
         Gui 5: +alwaysOnTop +toolwindow
         Gui 5: Show,  x75 y65 w472 h8 Activate,menuSamsung
         menuCmp:=1
      return ;;
      bs::sendIr(satCancel)
      enter::sendIr(satSelect)
      up::sendIr(satUp)
      right::sendIr(satRight)
      down::sendIr(satDown)
      left::sendIr(satLeft)
      !right::sendIr(satPgDn)
      !left::sendIr(satPgUp)
      space:: ;
         keyPress:=analyseKeyPress("PgDn")
         ifwinExist, pcTvControl
            sendIr(satPgUp)
         else{
            if keyPress{
               ifequal,aspect,1,send,+2
               else send,+1
               aspect:=aspect ? 0:1
            }
         }
      return ;;
   return ;;
   #ifWinActive keyboard.ahk
      ~^s::gosub reloadAhk
   return ;;
   #ifWinActive Foxit Reader
      enter::
      esc::send {F11}
      h::send ^3
      J::send ^{numpadAdd}
      k::send ^{numpadSub}
      b::send {right}
      n::send {left}
   return ;;
   #ifWinActive Save As
      space::send {del}%A_Now%{enter}
   return ;;
   #ifWinActive Google Chrome
      esc::send {F11}
      ~rButton::
         sleep 200
         send {down 4}
         send {enter}
         winwait, Save As,,1
         if (errorLevel=0){
            send %A_now%%A_MSec%
            send {enter}
         }
      return
   return ;;
    #ifWinActive Media Player Classic
      esc::send !{enter}
      r::send !r
      numpadAdd::send {Numpad9 2}
      numpadSub::send {Numpad1 2}
   return ;;
   #ifWinExist ahk_class Winamp v1.x
      home::ControlSend,Ahk_parent, c            ;Play/*Pause
      !home:: controlSend,ahk_parent, ^+k         ;VisualEffect
      !w::                              ; Show/Hide Winamp
      end::        
         setTimer,checkWinampVideo,500
         WinActivate, ahk_class Winamp v1.x
         controlSend,ahk_parent, !w
         WinGetPos ,,Y,,,ahk_class Winamp v1.x
         if(y=-30000){
            loop {
               controlSend,ahk_parent, !e
               WinGetPos ,,Y,,,ahk_class Winamp PE
               ifEqual,y,,break
            }
            loop {
               controlSend,ahk_parent, !l
               WinGetPos ,,Y,,,ahk_class Winamp Gen
               ifEqual,y,,break
            }
         }else{
            loop {
               controlSend,ahk_parent, !e
               WinGetPos ,,Y,,,ahk_class Winamp PE
               ifNotEqual,y,,break
            }
            loop {
               controlSend,ahk_parent, !l
               WinGetPos ,,Y,,,ahk_class Winamp Gen
               ifNotEqual,y,,break
            }
            WinActivate, ahk_class Winamp v1.x
         }
      return ;;
   return ;; ;;
; Function
   reloadAhk: ;
      DllCall("uuirtdrv.dll\UUIRTClose", UInt,hndl)
      IniWrite, %masterVolstep%, keyBoard.ini, section1, masterVolStep
      sleep 200
      Reload
   return ;;
   showVolBar: ;
      ifWinNotExist,guiVolMaster
      {
         volBarW:=A_screenWidth *.85
         volBarY:=A_screenHeight *.85
         volBarH:=A_screenHeight *.05
         SoundGet, ctrlMute, Master, mute
         ifequal,ctrlMute,Off,Progress,B zH%volBarH% zy0 zx0 y-100 W%volBarW% R0-1000 CbBlue CwWhite,,,guiVolMaster
         ifequal,ctrlMute,On ,Progress,B zH%volBarH% zy0 zx0 y-100 W%volBarW% R0-1000 CbRed CwWhite,,,guiVolMaster
         winSet,topMost,on,guiVolMaster
         WinSet, Transcolor, white 150, guiVolMaster
         WinMove, guiVolMaster,,,%volBarY%
      }
      adjustVol(masterVolStep,"Master")
      SoundGet, volCtrl, Master, volume
      volCtrl*=10
      Progress, %volCtrl%,,,guiVolMaster
      SetTimer, tmrHideVolBar, -2000
   return
   tmrHideVolBar:
      progress,off,,,guiVolMaster
   return
   adjustVol(volStep,volCtrlName){
      ifEqual,volStep,00,soundSet,00.00,%volCtrlName%,volume
      ifEqual,volStep,01,soundSet,00.15,%volCtrlName%,volume
      ifEqual,volStep,02,soundSet,00.30,%volCtrlName%,volume
      ifEqual,volStep,03,soundSet,00.45,%volCtrlName%,volume
      ifEqual,volStep,04,soundSet,00.65,%volCtrlName%,volume
      ifEqual,volStep,05,soundSet,01.00,%volCtrlName%,volume
      ifEqual,volStep,06,soundSet,01.50,%volCtrlName%,volume
      ifEqual,volStep,07,soundSet,02.00,%volCtrlName%,volume
      ifEqual,volStep,08,soundSet,03.00,%volCtrlName%,volume
      ifEqual,volStep,09,soundSet,04.50,%volCtrlName%,volume
      ifEqual,volStep,10,soundSet,06.50,%volCtrlName%,volume
      ifEqual,volStep,11,soundSet,10.00,%volCtrlName%,volume
      ifEqual,volStep,12,soundSet,15.00,%volCtrlName%,volume
      ifEqual,volStep,13,soundSet,20.00,%volCtrlName%,volume
      ifEqual,volStep,14,soundSet,30.00,%volCtrlName%,volume
      ifEqual,volStep,15,soundSet,45.00,%volCtrlName%,volume
      ifEqual,volStep,16,soundSet,65.00,%volCtrlName%,volume
      ifEqual,volStep,17,soundSet,100.00,%volCtrlName%,volume
      return
   } ;;
   analyseKeyPress(comboKeyName="",doubleKeySpeed=0.15,longKeyPressTime=0.15){ ;
      static diff:=0
      GetKeyState,comboKeyState,%comboKeyName%,P
      ifEqual,comboKeyState,D,hotkey,%comboKeyName%,disableComboKeyHotkey
     
      diff-=a_tickCount
      ifGreater,diff,-550,keywait, %A_thisHotkey%
      ifGreater,diff,-550,return 0
      diff:=a_tickCount
     
      keywait, %A_thisHotkey%,t%longKeyPressTime%
      if errorLevel{
         ifEqual,comboKeyState,D,setEnv,KeyPress,6      ;combo Long Key
         else setEnv,KeyPress,3                     ;long key
      }else{
         keywait, %A_thisHotkey%, d t%doubleKeySpeed%
         if errorLevel{
            ifEqual,comboKeyState,D,setEnv,KeyPress,4   ;combo single Key
            else setEnv,KeyPress,1                  ;Single key
         }else{
            ifEqual,comboKeyState,D,setEnv,KeyPress,5   ;combo double Key
            else setEnv,KeyPress,2                  ;double key
         }
      }
      ifEqual,comboKeyState,D,hotkey,%comboKeyName%,%comboKeyName%
      return %keyPress%
   }
   disableComboKeyHotKey:
      return
   Return ;;
   toggleDeskTop: ;
      iconHide:= iconhide ? 0:1
      ifequal,iconHide,1,Control, Hide,,SysTabControl321, ahk_class Progman
      else             Control, Show,,SysTabControl321, ahk_class Progman
      ifequal,iconHide,1,Control, Hide,,SysListView321, ahk_class Progman
      else             Control, Show,,SysListView321, ahk_class Progman
      ifequal,iconHide,1,Control, Hide,,static1, ahk_class Progman
      else            Control, Show,,static1, ahk_class Progman
      ifequal,iconHide,1,Control, Hide,,static2, ahk_class Progman
      else            Control, Show,,static2, ahk_class Progman
      ifequal,iconHide,1,Control, Hide,,Edit1, ahk_class Progman
      else            Control, Show,,Edit1, ahk_class Progman
      ifequal,iconHide,1,winHide,ahk_class Shell_TrayWnd
      else            winShow,ahk_class Shell_TrayWnd
     
      ifequal,iconHide,1,MouseGetPos,mouseX,mouseY
      ifequal,iconHide,1,MouseMove,%A_screenWidth%,%A_screenHeight%,0
      else             MouseMove,%mouseX%,%mouseY%,0
   return ;;
   changeDisplaySettings(width,height,hz=60,colorDepth=32){ ;
      VarSetCapacity(dM,156,0), NumPut(156,2,&dM,36)
      DllCall( "EnumDisplaySettings", UInt,0, UInt,-1, UInt,&dM ), NumPut(0x5c0000,dM,40)
      NumPut(colorDepth,dM,104),  NumPut(width,dM,108),  NumPut(height,dM,112),  NumPut(hz,dM,120)
      Return DllCall( "ChangeDisplaySettings", UInt,&dM, UInt,0 )
   } ;;  
   createDesktopNote: ;
      gui 3:destroy
      FileRead, quickNoteTxt, quickNote.txt
      FileRead, phoneNumberTxt,phoneNumber.Txt
      WinGetActiveTitle, winTitle
      Gui 3: Margin,0,0      ;%winTitleH%
      desktopNoteX:=(gridSpaceX*3)
      desktopNoteY:=0         ;-winTitleH
      desktopNoteW:=(A_screenWidth-desktopNoteX)
      desktopNoteH:=(A_screenHeight-desktopNoteY-taskBarH)      ;-winTitleH)
      editNoteH:=desktopNoteH-24
      Gui 3: Color,black,black
      Gui 3: Add, Tab2,x0 y0 CYellow w%desktopNoteW% h%desktopNoteH%, Quick Note|Phone#|_|__
      Gui 3: Tab
      Gui 3: Add, text,X205 y4 w115 cTeal r1
      Gui 3: Add, text,X430 y4 W255 cTeal r1 right
      Gui 3: Tab,1
      Gui 3: Add, Edit,x0 y24 W%desktopNoteW% H%editNoteH%  cYellow -wantCtrlA +wantTab vscroll -hScroll -Wrap t16 t96 t112 T164 T196 T336  -0x4000 +0x200000 -E0x200 gSaveQuickNote,%quickNoteTxt%
      Gui 3: Tab,2
      Gui 3: Add, Edit,x0 y24 W%desktopNoteW% H%editNoteH%  cYellow -wantCtrlA +wantTab vscroll -hScroll -Wrap t16 t96 t112 T164 T196 T336  -0x4000 +0x200000 -E0x200 gSavePhonenumber,%phoneNumberTxt%
      Gui 3: Tab,3
      Gui 3: font,S12, Verdana
      Gui 3: Add, Edit,x0 y24 W%desktopNoteW% H%editNoteH%  cYellow -wantCtrlA +wantTab vscroll -hScroll -Wrap t16 t96 t112 T164 T196 T336  -0x4000 +0x200000 -E0x200
      Gui 3: font
      Gui 3: Tab,4
      Gui 3: Add, Edit,x0 y24 W%desktopNoteW% H%editNoteH%  cYellow -wantCtrlA +wantTab vscroll hScroll -Wrap t16 t96 t112 T164 T196 T336  -0x4000 +0x200000 -E0x200
      Gui 3:+LastFound
      desktopNoteID:=winexist()
      winset,transcolor,black
      gui 3: -caption
      DllCall("SetParent", "uint", desktopNoteID, "uint", WinExist("Program Manager"))
      Gui 3: Show, x%desktopNoteX% y%desktopNoteY% W%desktopNoteW% H%desktopNoteH%,DesktopNote
      OnMessage(0x200, "WM_MOUSEMOVE")
      ControlClick, Edit1,ahk_class Progman,,,, NA
      WinActivate , %winTitle%
      setTimer,tmrCheckUpTime,%timeToCheckUpTime%
      gosub tmrCheckUpTime
   return
   saveQuickNote:
      ControlGetText, quickNoteTxt, Edit1,ahk_id %desktopNoteId%
      FileDelete, quickNote.txt
      FileAppend, %quickNoteTxt%, quickNote.txt
   return
   search:
  
   return
   savePhoneNumber:
      ControlGetText, phoneNumberTxt, Edit2,ahk_id %desktopNoteId%
      FileDelete, phoneNumber.txt
      FileAppend, %phoneNumberTxt%, phoneNumber.txt
   return
   tmrCheckUpTime:
      if(A_tickCount>uptimeRecord){
         upTimeRecord:=A_tickCount
         IniWrite, %upTimeRecord%, keyBoard.ini, section1, upTimeRecord
      }
      decortication(A_tickCount,days,hours,minutes)
      ControlSetText , static1, UpTime:%Days% jours %Hours%h%Minutes%, ahk_id %desktopNoteId%
      minuteDuJour:=(A_hour*60) + A_min
      goToBed:=""
      loop,5{  
         minuteDuJour+=cycleReveil
         heureDuJour:=minuteDuJour//60
         minuteDeHeure:=minuteDuJour-(heureDuJour*60)
        
         if (heureDuJour>=24)
            heureDuJour-=24
         if(minuteDeHeure<10)
            goToBed:=goToBed  heureDuJour "h0" minuteDeHeure "  "
         else
            goToBed:=goToBed  heureDuJour "h" minuteDeHeure "  "
      }
      ControlSetText , static2, %goToBed%, ahk_id %desktopNoteId%
   return
   decortication(tick,byref Days=0,byref Hours=0,byref Minutes=0,byref Seconds=0){
      TTMilliseconds := tick
      TTSeconds := tick // 1000 ;*1000 Mil secs in a second
      TTMinutes := tick // 60000 ;*60 secs in an minute
      TTHours := tick // 3600000 ;*60 Mins in an heureDuJour
      TTDays := tick // 86400000 ;*24 hours in a day
      TTWeeks := tick // 604800000 ;*52 weeks in a year. ;-)
      Milliseconds := TTMilliseconds - (1000 * (TTMilliseconds // 1000))
      Seconds := TTSeconds - (60 * (TTSeconds // 60))
      Minutes := TTMinutes - (60 * (TTMinutes // 60))
      Hours := TTHours - (24 * (TTHours // 24))
      Days := TTDays ;- (7 * (TTDays // 7))
      ;Weeks := TTWeeks - (52 * (TTWeeks // 52))
      if(minutes<10)
         minutes=0%Minutes%
   }
   WM_MOUSEMOVE(){
      MouseGetPos,,,,controlUnder
      ifEqual,controlUnder,Static1,SetTimer, displayToolTipStatic1,-10
      ifEqual,controlUnder,Static2,SetTimer, displayToolTipStatic2,-10
   }
   displayToolTipStatic1:
      decortication(upTimeRecord,days,hours,minutes)
      ToolTip Record:%Days% jours %Hours%h%Minutes%
      loop {
         mouseGetPos,,,,controlUnder
         ifNotEqual,controlUnder,Static1,break
      }
      tooltip
   return
   displayToolTipStatic2:
      goToBedCycle:=""
      cycleSommeil:=0
      loop,5{
         cycleSommeil+=cycleReveil
         heureCycle:=cycleSommeil//60
         minuteCycle:=(cycleSommeil-(heureCycle*60))
         if(minuteCycle<10)
            goToBedCycle:=goToBedCycle  heureCycle "h0" minuteCycle "  "
         else
            goToBedCycle:=goToBedCycle  heureCycle "h" minuteCycle "  "
      }
      ToolTip %goToBedCycle%
      loop{
         mouseGetPos,,,,controlUnder
         ifNotEqual,controlUnder,Static2,break
      }
      tooltip
   return ;;
   learnIr: ;
      abort:=0
      ;setTimer,te,-1000      ;Test
      learnIrCallBackAddress := RegisterCallback("learnIrCallBack")
      VarSetCapacity(IrCode, 2048)
      DllCall("uuirtdrv.dll\UUIRTLearnIR"
         ,UInt,hndl
         ,Int,0x0110
         ,Str,irCode
         ,UInt,learnIrCallBackAddress
         ,Str,"void"
         ,UIntP,abort
         ,UInt,0
         ,UInt,0,UInt,0)
      ;tooltip %irCode%
   return
   te:
      ;msgbox allo
      ;a:=NumPut(1, &abort)   ;test
   return
   learnIrcallBack(progress,quality,frequency,userData){
      tooltip %progress%`%__%quality%`%__%frequency%Hz,100,100,2
   } ;;
   sendIr(irCode,repeatCount=3,codeFormat=0X0110){ ;
      global
      DllCall("uuirtdrv.dll\UUIRTTransmitIR"
         ,UInt,hndl
         ,Str,irCode
         ,Int,codeFormat
         ,Int,repeatCount
         ,int,0
         ,HANDLE,hEvent
         ,void,reserved0
         ,void reserved1)
   } ;;
   interceptIr(irEventStr,userData){ ;
      global irCode
      irCode:=NumGet(irEventStr+0,0,"char") NumGet(irEventStr+0,1,"char") NumGet(irEventStr+0,2,"char") NumGet(irEventStr+0,3,"char") NumGet(irEventStr+0,4,"char") NumGet(irEventStr+0,5,"char") NumGet(irEventStr+0,6,"char") NumGet(irEventStr+0,7,"char") NumGet(irEventStr+0,8,"char") NumGet(irEventStr+0,9,"char") NumGet(irEventStr+0,10,"char") NumGet(irEventStr+0,11,"char") NumGet(irEventStr+0,12,"char")
      setTimer,analyseIrCode,-10
      return
   }
   analyseIrCode:
      ;send %irCode% return
      loop,2{
         a:= irCode=auxPgUp%A_index% ? sendIR(lightRaise)
         a:= irCode=auxPgDn%A_index% ? sendIR(lightLower)
      }
      a:= irCode=auxMode3   ? sendIR(lightPreset)
      a:= irCode=auxPgUp3   ? sendIR(lightOn)
      a:= irCode=auxPgDn3 ? sendIR(lightOff)
     
      SetKeyDelay 40,10
      loop,3{
         IfWinExist,ahk_class Winamp v1.x
         ifEqual,irCode,% auxStop%A_index%,controlSend,ahk_parent,!w!e!l
         ifEqual,irCode,% auxBack%A_index%,controlSend,ahk_parent,z
         ifEqual,irCode,% auxBack%A_index%,tooltip,skip BACK,424,240
         ifEqual,irCode,% auxBack%A_index%,setTimer,removeTooltip,-1000
         ifEqual,irCode,% auxPause%A_index%,controlSend,ahk_parent,c
         ifEqual,irCode,% auxFwd%A_index%,controlSend,ahk_parent,b
         ifEqual,irCode,% auxFwd%A_index%,tooltip,skip FORWARD,424,240
         ifEqual,irCode,% auxFwd%A_index%,setTimer,removeTooltip,-1000
        
         ifEqual,irCode,% auxPVR%A_index%,ControlSend, ahk_parent,^+k
     
         IfWinExist,ahk_class MilkDrop2
         ifEqual,irCode,% auxSkipFwd%A_index%,ControlSend, ahk_parent,h
         ifEqual,irCode,% auxSkipBack%A_index%,ControlSend, ahk_parent,{bs}
     
         IfWinActive,ahk_class MediaPlayerClassicW
         ifEqual,irCode,% auxSkipBack%A_index%,send,{PgUp}
         ifEqual,irCode,% auxSkipFwd%A_index%,send,{PgDn}
     
         ifEqual,irCode,% auxVolUp%A_index%,gosub,volume_up
         ifEqual,irCode,% auxVolDn%A_index%,gosub,volume_Down
         ifEqual,irCode,% auxPlay%A_index%,gosub,toggleDesktop
        
        
         a:= irCode=aux3%A_index% ? sendIR(lightOn)
         a:= irCode=aux2%A_index% ? sendIR(lightRaise)
         a:= irCode=aux5%A_index% ? sendIR(lightPreset)
         a:= irCode=aux8%A_index% ? sendIR(lightLower)
         a:= irCode=aux9%A_index% ? sendIR(lightOff)
      }
      mouseMove,1,0,0,r
      mouseMove,-1,0,0,r
      SetKeyDelay 0,0
  
   return ;;
   decode(stringToDecode){ ;
      Length := strLen(stringToDecode)/3
      pos:=1
      loop, %length%{
         stringMid, ascNum, stringToDecode, %pos%,3
         temp:=Chr(ascNum)
         stringDecode=%stringDecode%%temp%
         pos+=3
      }
      return %stringDecode%
   } ;;
   ; tvRelative
      turnOffTv: ;
         setTimer,tmrCheckForSleep,off
         sendIr(tvOff,1)
         tvStatut*=-1
         IniWrite, %tvStatut%, keyBoard.ini, section1, tvStatut
         setTimer,tmrTurnOffLight,on
         sleep 2500
         setTimer,tmrCheckForWakeUp,100
      return
      tmrCheckForWakeUp:
         ifLess,A_timeIdle,500,gosub turnOnTV
      return
      tmrTurnOffLight: ;
         setTimer,tmrTurnOffLight,5000
         if (tvStatut<0 and cmp<30){
            cmp++
            a:= cmp=1 ? sendIR(lightPreset)
            a:= cmp<>1 ? sendIR(lightLower,1)
         }else{
            cmp:=0
            setTimer,tmrTurnOffLight,Off
         }
      return ;; ;;
      turnOnTv: ;
         setTimer,tmrCheckForWakeUp,off
         sendIr(tvOn,1)
         tvStatut*=-1
         IniWrite, %tvStatut%, keyBoard.ini, section1, tvStatut
         setTimer,tmrCheckForSleep,%minute%
      return
      tmrCheckForSleep:
         ifGreater,A_timeIdle,%heure%,gosub,turnOffTv
      return ;;  
      switchToHDMI1: ;
         tvStatut:=1
         IniWrite, %tvStatut%, keyBoard.ini, section1, tvStatut
         sendIr(TvHdmi1)
         IfWinNotExist,ahk_class AfxWnd42
            soundSet,1,line,mute
         gui,2:Destroy
      return ;;
      switchToHDMI2: ;
         tvStatut:=2
         IniWrite, %tvStatut%, keyBoard.ini, section1, tvStatut
         sendIr(TvHdmi2)
         soundSet,0,line,mute
         Gui 2: Show, maximized,pcTvControl
      return ;;
      switchToHDMI3: ;
         tvStatut:=3
         IniWrite, %tvStatut%, keyBoard.ini, section1, tvStatut
         sendIr(TvHdmi3,2)
         soundSet,0,line,mute
      return ;;