Jump to content

How to register to Focus Loss event?


Recommended Posts

I am developing a text pasting application which requires the focus to be on some other application. That's why, I have created its GUI as

Local $hMainGUI = GUICreate("Text Paste", 700, 300, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_NOACTIVATE))

The application will trigger keystrokes to the target application continuously. Let's say, the focus is on Windows Notepad which is receiving those keystrokes. I want, if the focus is shifted from Notepad to some other application by an inadvertent click of the user, an event to be generated which is captured by my application to stop the series of key-presses. Can anybody please suggest how can I achieve that?

[size="2"][font="arial, verdana, tahoma, sans-serif"]ProtectData - A Data Protection software for floppies[/font][/size] [size="2"][hr][/size][size="2"]Sessionchange - A Windows service capable of tracking session change events[/size][size="2"][b][/b][/size]

Link to comment
Share on other sites

Take a look at WM_ACTIVATE message

GUIRegisterMsg($WM_ACTIVATE, Wm_Activate)

Func Wm_Activate($hWnd, $uMsg, $wParam, $lParam)
  If ($wParam = 0) Then ; Inactivated
    ; Do smth
  EndIf
  Return $GUI_RUNDEFMSG
EndFUnc

PS: Next time, try asking Prof. MoriatyJames first

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to comment
Share on other sites

Take a look at WM_ACTIVATE message

GUIRegisterMsg($WM_ACTIVATE, Wm_Activate)

Func Wm_Activate($hWnd, $uMsg, $wParam, $lParam)
  If ($wParam = 0) Then ; Inactivated
    ; Do smth
  EndIf
  Return $GUI_RUNDEFMSG
EndFUnc
PS: Next time, try asking Prof. MoriatyJames first

 

Dear Dr. Watson,

 

The code snippet above does not work. If the focus is lost from the current window, my application is never being able to listen to WM_ACTIVATE messages.

[size="2"][font="arial, verdana, tahoma, sans-serif"]ProtectData - A Data Protection software for floppies[/font][/size] [size="2"][hr][/size][size="2"]Sessionchange - A Windows service capable of tracking session change events[/size][size="2"][b][/b][/size]

Link to comment
Share on other sites

Just check if your window is the active window, if not then blockinput. ;)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Just check if your window is the active window, if not then blockinput. ;)

 

No, it's not. As I have already mentioned in the OP,

Local $hMainGUI = GUICreate("Text Paste", 700, 300, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_NOACTIVATE))
Edited by HolmesShelock

[size="2"][font="arial, verdana, tahoma, sans-serif"]ProtectData - A Data Protection software for floppies[/font][/size] [size="2"][hr][/size][size="2"]Sessionchange - A Windows service capable of tracking session change events[/size][size="2"][b][/b][/size]

Link to comment
Share on other sites

 

No, it's not. As I have already mentioned in the OP,

Local $hMainGUI = GUICreate("Text Paste", 700, 300, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_NOACTIVATE))

 

Excuse my English, but as you can see, it will not be active in the first place. I got that from your first post (I can read thank you :shifty:). What I meant was see what the active window is, and put it into a variable, then constantly check whether that is the active window, if it isn't then its obviously not active. Which, you can then block the input or whatever you want to do from there.

Questions? ;)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...