AutoHotkey Community

It is currently May 26th, 2012, 10:48 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: function: cloak()
PostPosted: September 17th, 2009, 11:10 pm 
Offline

Joined: February 6th, 2008, 12:26 am
Posts: 14
Location: the land of enchantment
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
;


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Yahoo [Bot] and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group