AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

function: cloak()

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
oldHacker



Joined: 05 Feb 2008
Posts: 14
Location: the land of enchantment

PostPosted: Thu Sep 17, 2009 10:10 pm    Post subject: function: cloak() Reply with quote

i've seen several references (see LockWindowUpdate, RedrawWindow, and InvalidateRect) to locking the screen whilst preforming behind the scenes action, but never a function so here goes.

1) place both files cloakTest.ahk and cloak.ahk. into a folder.

2) run cloakTest.ahk.

3) press f12 (more than once) and see what happens.

also try it with different flags. in some cases you can get by without the include ALLCHILDREN flag, but not in this case.

note-1: i have found sending keys to be more reliable than clicking buttons.

note-2: if you lock the screen use ctrl+alt+delete then cancel to get back control.

note-3: tested on win2k

Code:

; cloak.ahk
;
;   usage:
;      cloak()            ; lock screen
;         do something
;      cloak(0)         ; unlock screen
;
;   default, cloak(), uses the flags listed below. in some cases
;   you can get better results using cloak(0x505) experiment.
;
;   note: cloaks may be nested
;
cloak(f = 0x585)   {                  ; RDW_FRAME          = 0400h
   static rdf, dhw, clk = 0               ; RDW_UPDATENOW       = 0100h
   if f   {                           ; RDW_ALLCHILDREN     = 0080h
      if !clk   {                     ; RDW_ERASE          = 0004h
         rdf := f                  ; RDW_INVALIDATE       = 0001h
         dhw := a_detectHiddenWindows
         detectHiddenWindows on
         dt_h := dllCall("GetDesktopWindow")
         sendMessage 0xB,,,, ahk_id %dt_h%      ; redraw off
      }
      clk++                        ; for nesting
   } else if clk   {
      clk--
      if !clk   {
         dt_h := dllCall("GetDesktopWindow")
         sendMessage 0xB, 1,,, ahk_id %dt_h%      ; redraw on
         dllCall("RedrawWindow", uint, 0, uint, 0, uint, 0, int, rdf)
         detectHiddenWindows %dhw%
      }
   }
   return clk
}
;
;   helper function you may or may not find useful
;   sends <keys> to the window <tlt>, <txt>
;   returns 1 if the keys were sent or 0 if there was a problem
;
waitNsend(keys, tlt, txt = "")   {
   winWait %tlt%, %txt%, 2
   if !errorLevel   {
      winActivate
      winWaitActive ,,, 2
      if !errorLevel
         sendInput %keys%
   }
   return !errorLevel
}
;


test file. be sure to name it cloakTest.ahk

Code:

; cloakTest.ahk
;
#singleInstance force
;
run notepad
;
state = 0
#ifWinActive ahk_class Notepad
f12::
   f = cloakTest.ahk
   if state   {
      cloak()            ; default --> include ALLCHILDREN
      ;cloak(0x505)      ; try different flags & see what happens ;}
      f = cloak.ahk
   }
   sendInput !fo
   winWaitActive Open ahk_class #32770,, 5
   if !errorlevel   {
      sendInput %A_ScriptDir%\%f%{enter}
      winWaitClose ,,, 2
   }
   cloak(0)
   state := !state
return
;
#include %a_scriptDir%
#include cloak.ahk
;
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group