Ok, after playing around a bit I think I may have it. Give this a try and let me know how it works for you.
Again this is in AHK
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#Persistent
#SingleInstance, Force
SetTimer, WatchControl, 500
return
WatchControl:
ControlGetFocus, a_control, A
StringLeft, activeControl, a_control, 4
; ToolTip, %activeControl%
if (activeControl = "Edit")
ifWinExist, On-Screen Keyboard
return
else
run, osk.exe
if (activeControl <> "Edit")
IfWinExist, On-Screen Keyboard
process, close, osk.exe
else
return
return