1

I am writing an Autohotkey script that fiddles with some Photoshop windows and controls.

I need to be able to unfocus the currently focused control (say, Edit3), so that no control has focus after that (I could explain why exactly I need to do that if necessary, but it seems irrelevant, I just really need all controls unfocused).

AHK's ControlFocus command doesn't provide such an option.

I tried using a Windows Message like this:

SendMessage, 0x8, 0, 0, Edit3, A  ; WM_KILLFOCUS = 0x08

but it doesn't do anything. In comparison, the opposite one works as expected and focuses the control:

SendMessage, 0x7, 0, 0, Edit3, A  ; WM_SETFOCUS = 0x07

Perhaps I'm doing something wrong with the WM_KILLFOCUS message?

Just to clarify: I don't want to simulate clicks, switch windows, add new invisible controls which to focus etc. I just want to know how to unfocus a control.

So, any idea how to unfocus a control, without focusing another one?

jedivader
  • 828
  • 10
  • 23
  • `SendMessage, 0x7` also doesn't alter the focus for me (tested in skype). Frankly, "Sent to a window after it has gained the keyboard focus" doesn't sound like a huge help in setting focus at all (also see http://stackoverflow.com/questions/15469234/using-wm-setfocus-and-wm-killfocus ). Regarding your question: No, no idea. – phil294 Feb 08 '16 at 19:43

2 Answers2

0
last_active_win:=winexist("A") ;get the previous windows process before launching your gui

Gui +AlwaysOnTop 

Gui Add, Button, x10 w100 h30 , % 1
 
Gui Show,, My GUI ;launch the gui which gets the focus 

sleep 500

WinActivate ahk_id %last_active_win% ;reactivate previous windows to unfocus controls from gui

return
avariant
  • 2,234
  • 5
  • 25
  • 33
albert
  • 1
  • 1
-1

You can send #d and you will go to Desktop. Which is going to focus on the desktop but can work for you.

SendInput, #d
ancalotoru
  • 36
  • 3