<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: переменная раскладки клавиатуры]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=5650&amp;type=atom" />
	<updated>2018-08-15T16:54:12Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=5650</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127982#p127982" />
			<content type="html"><![CDATA[<p>Потому что, если мы возьмемем и проверим процесс ApplicationFrameHost.exe на присутствующие контролы, то они будут иметь одни и теже хендлы невзирая на переключение вкладок в Edge. <br />А если мы проверим фокусированный хендл в процессе Edge, ProcessId которого показывается через Inspect.exe, то мы получим правильное изменение языка для этого хендла. <br /><a href="https://github.com/blackrosezy/gui-inspect-tool">https://github.com/blackrosezy/gui-inspect-tool</a><br />От <strong>neptercn</strong> автохотки UIA враппер с edge не работает:<br /><a href="https://autohotkey.com/boards/viewtopic.php?p=233872#p233872">https://autohotkey.com/boards/viewtopic … 72#p233872</a><br />Но зато работает враппер от <strong>jethrow</strong>.<br />Вот так у меня работает с edge:<br /></p><div class="codebox"><pre><code>F11::MsgBox, % GetLayout()

GetLayout()
{
   detecthiddenwindows on
   uia := UIA_Interface()
   GetFocusedElement := uia.GetFocusedElement()
   pid := GetFocusedElement.CurrentProcessId
   ControlGetFocus, FocusedControl, ahk_pid %pid%
   ControlGet, Hwnd, Hwnd,, %FocusedControl%, ahk_pid %pid%
   ThreadID := DllCall(&quot;GetWindowThreadProcessId&quot;, Ptr, hWnd, UInt, 0, Ptr)
   InputLocaleID := DllCall(&quot;GetKeyboardLayout&quot;, Ptr, ThreadID, Ptr)
   Return (InputLocaleID &amp; 0xFFFF = 0x409) ? &quot;En&quot; : &quot;Ru&quot;
}



;~ UI Automation Constants: http://msdn.microsoft.com/en-us/library/windows/desktop/ee671207(v=vs.85).aspx
;~ UI Automation Enumerations: http://msdn.microsoft.com/en-us/library/windows/desktop/ee671210(v=vs.85).aspx
;~ http://www.autohotkey.com/board/topic/94619-ahk-l-screen-reader-a-tool-to-get-text-anywhere/

/* Questions:
	- better way to do __properties?
	- support for Constants?
	- if method returns a SafeArray, should we return a Wrapped SafeArray, Raw SafeArray, or AHK Array
	- on UIA Interface conversion methods, how should the data be returned? wrapped/extracted or raw? should raw data be a ByRef param?
	- do variants need cleared? what about SysAllocString BSTRs?
	- do RECT struts need destroyed?
	- if returning wrapped data &amp; raw is ByRef, will the wrapped data being released destroy the raw data?
	- returning varaint data other than vt=3|8|9|13|0x2000
	- Cached Members?
	- UIA Element existance - dependent on window being visible (non minimized)?
	- function(params, ByRef out=&quot;……&quot;)
*/

class UIA_Base {
	__New(p=&quot;&quot;, flag=1) {
		ObjInsert(this,&quot;__Type&quot;,&quot;IUIAutomation&quot; SubStr(this.__Class,5))
		,ObjInsert(this,&quot;__Value&quot;,p)
		,ObjInsert(this,&quot;__Flag&quot;,flag)
	}
	__Get(member) {
		if member not in base,__UIA ; base &amp; __UIA should act as normal
		{	if raw:=SubStr(member,0)=&quot;*&quot; ; return raw data - user should know what they are doing
				member:=SubStr(member,1,-1)
			if RegExMatch(this.__properties, &quot;im)^&quot; member &quot;,(\d+),(\w+)&quot;, m) { ; if the member is in the properties. if not - give error message
				if (m2=&quot;VARIANT&quot;)	; return VARIANT data - DllCall output param different
					return UIA_Hr(DllCall(this.__Vt(m1), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,UIA_Variant(out)))? (raw?out:UIA_VariantData(out)):
				else if (m2=&quot;RECT&quot;) ; return RECT struct - DllCall output param different
					return UIA_Hr(DllCall(this.__Vt(m1), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,&amp;(rect,VarSetCapacity(rect,16))))? (raw?out:UIA_RectToObject(rect)):
				else if UIA_Hr(DllCall(this.__Vt(m1), &quot;ptr&quot;,this.__Value, &quot;ptr*&quot;,out))
					return raw?out:m2=&quot;BSTR&quot;?StrGet(out):RegExMatch(m2,&quot;i)IUIAutomation\K\w+&quot;,n)?new UIA_%n%(out):out ; Bool, int, DWORD, HWND, CONTROLTYPEID, OrientationType?
			}
			else throw Exception(&quot;Property not supported by the &quot; this.__Class &quot; Class.&quot;,-1,member)
		}
	}
	__Set(member) {
		throw Exception(&quot;Assigning values not supported by the &quot; this.__Class &quot; Class.&quot;,-1,member)
	}
	__Call(member) {
		if !ObjHasKey(UIA_Base,member)&amp;&amp;!ObjHasKey(this,member)
			throw Exception(&quot;Method Call not supported by the &quot; this.__Class &quot; Class.&quot;,-1,member)
	}
	__Delete() {
		this.__Flag? ObjRelease(this.__Value):
	}
	__Vt(n) {
		return NumGet(NumGet(this.__Value+0,&quot;ptr&quot;)+n*A_PtrSize,&quot;ptr&quot;)
	}
}	

class UIA_Interface extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee671406(v=vs.85).aspx
	static __IID := &quot;{30cbe57d-d9d0-452a-ab13-7ac5ac4825ee}&quot;
		,  __properties := &quot;ControlViewWalker,14,IUIAutomationTreeWalker`r`nContentViewWalker,15,IUIAutomationTreeWalker`r`nRawViewWalker,16,IUIAutomationTreeWalker`r`nRawViewCondition,17,IUIAutomationCondition`r`nControlViewCondition,18,IUIAutomationCondition`r`nContentViewCondition,19,IUIAutomationCondition`r`nProxyFactoryMapping,48,IUIAutomationProxyFactoryMapping`r`nReservedNotSupportedValue,54,IUnknown`r`nReservedMixedAttributeValue,55,IUnknown&quot;
	
	CompareElements(e1,e2) {
		return UIA_Hr(DllCall(this.__Vt(3), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e1.__Value, &quot;ptr&quot;,e2.__Value, &quot;int*&quot;,out))? out:
	}
	CompareRuntimeIds(r1,r2) {
		return UIA_Hr(DllCall(this.__Vt(4), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,ComObjValue(r1), &quot;ptr&quot;,ComObjValue(r2), &quot;int*&quot;,out))? out:
	}
	GetRootElement() {
		return UIA_Hr(DllCall(this.__Vt(5), &quot;ptr&quot;,this.__Value, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
	ElementFromHandle(hwnd) {
		return UIA_Hr(DllCall(this.__Vt(6), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,hwnd, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
	ElementFromPoint(x=&quot;&quot;, y=&quot;&quot;) {
		return UIA_Hr(DllCall(this.__Vt(7), &quot;ptr&quot;,this.__Value, &quot;int64&quot;,x==&quot;&quot;||y==&quot;&quot;?0*DllCall(&quot;GetCursorPos&quot;,&quot;Int64*&quot;,pt)+pt:x&amp;0xFFFFFFFF|y&lt;&lt;32, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}	
	GetFocusedElement() {
		return UIA_Hr(DllCall(this.__Vt(8), &quot;ptr&quot;,this.__Value, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
	;~ GetRootElementBuildCache 	9
	;~ ElementFromHandleBuildCache 	10
	;~ ElementFromPointBuildCache 	11
	;~ GetFocusedElementBuildCache 	12
	CreateTreeWalker(condition) {
		return UIA_Hr(DllCall(this.__Vt(13), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,Condition.__Value, &quot;ptr*&quot;,out))? new UIA_TreeWalker(out):
	}
	;~ CreateCacheRequest 	20

	CreateTrueCondition() {
		return UIA_Hr(DllCall(this.__Vt(21), &quot;ptr&quot;,this.__Value, &quot;ptr*&quot;,out))? new UIA_Condition(out):
	}
	CreateFalseCondition() {
		return UIA_Hr(DllCall(this.__Vt(22), &quot;ptr&quot;,this.__Value, &quot;ptr*&quot;,out))? new UIA_Condition(out):
	}
	CreatePropertyCondition(propertyId, ByRef var, type=&quot;Variant&quot;) {
		if (type!=&quot;Variant&quot;)
			UIA_Variant(var,type,var)
		return UIA_Hr(DllCall(this.__Vt(23), &quot;ptr&quot;,this.__Value, &quot;int&quot;,propertyId, &quot;ptr&quot;,&amp;var, &quot;ptr*&quot;,out))? new UIA_PropertyCondition(out):
	}
	CreatePropertyConditionEx(propertyId, ByRef var, type=&quot;Variant&quot;, flags=0x1) { ; NOT TESTED
	; PropertyConditionFlags_IgnoreCase = 0x1
		if (type!=&quot;Variant&quot;)
			UIA_Variant(var,type,var)
		return UIA_Hr(DllCall(this.__Vt(24), &quot;ptr&quot;,this.__Value, &quot;int&quot;,propertyId, &quot;ptr&quot;,&amp;var, &quot;uint&quot;,flags, &quot;ptr*&quot;,out))? new UIA_PropertyCondition(out):
	}
	CreateAndCondition(c1,c2) {
		return UIA_Hr(DllCall(this.__Vt(25), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,c1.__Value, &quot;ptr&quot;,c2.__Value, &quot;ptr*&quot;,out))? new UIA_AndCondition(out):
	}
	CreateAndConditionFromArray(array) { ; ComObj(0x2003)??
	;-&gt;in: AHK Array or Wrapped SafeArray
		if ComObjValue(array)&amp;0x2000
			SafeArray:=array
		else {
			SafeArray:=ComObj(0x2003,DllCall(&quot;oleaut32\SafeArrayCreateVector&quot;, &quot;uint&quot;,13, &quot;uint&quot;,0, &quot;uint&quot;,array.MaxIndex()),1)
			for i,c in array
				SafeArray[A_Index-1]:=c.__Value, ObjAddRef(c.__Value) ; AddRef - SafeArrayDestroy will release UIA_Conditions - they also release themselves
		}
		return UIA_Hr(DllCall(this.__Vt(26), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,ComObjValue(SafeArray), &quot;ptr*&quot;,out))? new UIA_AndCondition(out):
	}
	CreateAndConditionFromNativeArray(p*) { ; Not Implemented
		return UIA_NotImplemented()
	/*	[in]           IUIAutomationCondition **conditions,
		[in]           int conditionCount,
		[out, retval]  IUIAutomationCondition **newCondition
	*/
		;~ return UIA_Hr(DllCall(this.__Vt(27), &quot;ptr&quot;,this.__Value,
	}
	CreateOrCondition(c1,c2) {
		return UIA_Hr(DllCall(this.__Vt(28), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,c1.__Value, &quot;ptr&quot;,c2.__Value, &quot;ptr*&quot;,out))? new UIA_OrCondition(out):
	}
	CreateOrConditionFromArray(array) {
	;-&gt;in: AHK Array or Wrapped SafeArray
		if ComObjValue(array)&amp;0x2000
			SafeArray:=array
		else {
			SafeArray:=ComObj(0x2003,DllCall(&quot;oleaut32\SafeArrayCreateVector&quot;, &quot;uint&quot;,13, &quot;uint&quot;,0, &quot;uint&quot;,array.MaxIndex()),1)
			for i,c in array
				SafeArray[A_Index-1]:=c.__Value, ObjAddRef(c.__Value) ; AddRef - SafeArrayDestroy will release UIA_Conditions - they also release themselves
		}
		return UIA_Hr(DllCall(this.__Vt(29), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,ComObjValue(SafeArray), &quot;ptr*&quot;,out))? new UIA_AndCondition(out):
	}
	CreateOrConditionFromNativeArray(p*) { ; Not Implemented
		return UIA_NotImplemented()
	/*	[in]           IUIAutomationCondition **conditions,
		[in]           int conditionCount,
		[out, retval]  IUIAutomationCondition **newCondition
	*/
		;~ return UIA_Hr(DllCall(this.__Vt(27), &quot;ptr&quot;,this.__Value,
	}
	CreateNotCondition(c) {
		return UIA_Hr(DllCall(this.__Vt(31), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,c.__Value, &quot;ptr*&quot;,out))? new UIA_NotCondition(out):
	}

	;~ AddAutomationEventHandler 	32
	;~ RemoveAutomationEventHandler 	33
	;~ AddPropertyChangedEventHandlerNativeArray 	34
	AddPropertyChangedEventHandler(element,scope=0x1,cacheRequest=0,handler=&quot;&quot;,propertyArray=&quot;&quot;) {
		SafeArray:=ComObjArray(0x3,propertyArray.MaxIndex())
		for i,propertyId in propertyArray
			SafeArray[i-1]:=propertyId
		return UIA_Hr(DllCall(this.__Vt(35), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,element.__Value, &quot;int&quot;,scope, &quot;ptr&quot;,cacheRequest,&quot;ptr&quot;,handler.__Value,&quot;ptr&quot;,ComObjValue(SafeArray)))
	}
	;~ RemovePropertyChangedEventHandler 	36
	;~ AddStructureChangedEventHandler 	37
	;~ RemoveStructureChangedEventHandler 	38
	AddFocusChangedEventHandler(cacheRequest, handler) {
		return UIA_Hr(DllCall(this.__Vt(39), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,cacheRequest, &quot;ptr&quot;,handler.__Value))
	}
	;~ RemoveFocusChangedEventHandler 	40
	;~ RemoveAllEventHandlers 	41

	IntNativeArrayToSafeArray(ByRef nArr, n=&quot;&quot;) {
		return UIA_Hr(DllCall(this.__Vt(42), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,&amp;nArr, &quot;int&quot;,n?n:VarSetCapacity(nArr)/4, &quot;ptr*&quot;,out))? ComObj(0x2003,out,1):
	}
/*	IntSafeArrayToNativeArray(sArr, Byref nArr=&quot;&quot;, Byref arrayCount=&quot;&quot;) { ; NOT WORKING
		VarSetCapacity(nArr,(sArr.MaxIndex()+1)*4)
		return UIA_Hr(DllCall(this.__Vt(43), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,ComObjValue(sArr), &quot;ptr*&quot;,nArr, &quot;int*&quot;,arrayCount))? arrayCount:
	}
*/
	RectToVariant(ByRef rect, ByRef out=&quot;&quot;) {	; in:{left,top,right,bottom} ; out:(left,top,width,height)
		; in:	RECT Struct
		; out:	AHK Wrapped SafeArray &amp; ByRef Variant
		return UIA_Hr(DllCall(this.__Vt(44), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,&amp;rect, &quot;ptr&quot;,UIA_Variant(out)))? UIA_VariantData(out):
	}
/*	VariantToRect(ByRef var, ByRef out=&quot;&quot;) { ; NOT WORKING
		; in:	VT_VARIANT (SafeArray)
		; out:	AHK Wrapped RECT Struct &amp; ByRef Struct
		return UIA_Hr(DllCall(this.__Vt(45), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,var, &quot;ptr&quot;,&amp;(out,VarSetCapacity(out,16))))? UIA_RectToObject(out):
	}
*/
	;~ SafeArrayToRectNativeArray 	46
	;~ CreateProxyFactoryEntry 	47
	GetPropertyProgrammaticName(Id) {
		return UIA_Hr(DllCall(this.__Vt(49), &quot;ptr&quot;,this.__Value, &quot;int&quot;,Id, &quot;ptr*&quot;,out))? StrGet(out):
	}
	GetPatternProgrammaticName(Id) {
		return UIA_Hr(DllCall(this.__Vt(50), &quot;ptr&quot;,this.__Value, &quot;int&quot;,Id, &quot;ptr*&quot;,out))? StrGet(out):
	}
	PollForPotentialSupportedPatterns(e, Byref Ids=&quot;&quot;, Byref Names=&quot;&quot;) {
		return UIA_Hr(DllCall(this.__Vt(51), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e.__Value, &quot;ptr*&quot;,Ids, &quot;ptr*&quot;,Names))? UIA_SafeArraysToObject(Names:=ComObj(0x2008,Names,1),Ids:=ComObj(0x2003,Ids,1)):
	}
	PollForPotentialSupportedProperties(e, Byref Ids=&quot;&quot;, Byref Names=&quot;&quot;) {
		return UIA_Hr(DllCall(this.__Vt(52), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e.__Value, &quot;ptr*&quot;,Ids, &quot;ptr*&quot;,Names))? UIA_SafeArraysToObject(Names:=ComObj(0x2008,Names,1),Ids:=ComObj(0x2003,Ids,1)):
	}
	CheckNotSupported(value) { ; Useless in this Framework???
	/*	Checks a provided VARIANT to see if it contains the Not Supported identifier.
		After retrieving a property for a UI Automation element, call this method to determine whether the element supports the 
		retrieved property. CheckNotSupported is typically called after calling a property retrieving method such as GetCurrentPropertyValue.
	*/
		return UIA_Hr(DllCall(this.__Vt(53), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,value, &quot;int*&quot;,out))? out:
	}
	ElementFromIAccessible(IAcc, childId=0) {
	/* The method returns E_INVALIDARG - &quot;One or more arguments are not valid&quot; - if the underlying implementation of the
	Microsoft UI Automation element is not a native Microsoft Active Accessibility server; that is, if a client attempts to retrieve
	the IAccessible interface for an element originally supported by a proxy object from Oleacc.dll, or by the UIA-to-MSAA Bridge.
	*/
		return UIA_Hr(DllCall(this.__Vt(56), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,ComObjValue(IAcc), &quot;int&quot;,childId, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
	;~ ElementFromIAccessibleBuildCache 	57
}

class UIA_Element extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee671425(v=vs.85).aspx
	static __IID := &quot;{d22108aa-8ac5-49a5-837b-37bbb3d7591e}&quot;
		,  __properties := &quot;CurrentProcessId,20,int`r`nCurrentControlType,21,CONTROLTYPEID`r`nCurrentLocalizedControlType,22,BSTR`r`nCurrentName,23,BSTR`r`nCurrentAcceleratorKey,24,BSTR`r`nCurrentAccessKey,25,BSTR`r`nCurrentHasKeyboardFocus,26,BOOL`r`nCurrentIsKeyboardFocusable,27,BOOL`r`nCurrentIsEnabled,28,BOOL`r`nCurrentAutomationId,29,BSTR`r`nCurrentClassName,30,BSTR`r`nCurrentHelpText,31,BSTR`r`nCurrentCulture,32,int`r`nCurrentIsControlElement,33,BOOL`r`nCurrentIsContentElement,34,BOOL`r`nCurrentIsPassword,35,BOOL`r`nCurrentNativeWindowHandle,36,UIA_HWND`r`nCurrentItemType,37,BSTR`r`nCurrentIsOffscreen,38,BOOL`r`nCurrentOrientation,39,OrientationType`r`nCurrentFrameworkId,40,BSTR`r`nCurrentIsRequiredForForm,41,BOOL`r`nCurrentItemStatus,42,BSTR`r`nCurrentBoundingRectangle,43,RECT`r`nCurrentLabeledBy,44,IUIAutomationElement`r`nCurrentAriaRole,45,BSTR`r`nCurrentAriaProperties,46,BSTR`r`nCurrentIsDataValidForForm,47,BOOL`r`nCurrentControllerFor,48,IUIAutomationElementArray`r`nCurrentDescribedBy,49,IUIAutomationElementArray`r`nCurrentFlowsTo,50,IUIAutomationElementArray`r`nCurrentProviderDescription,51,BSTR`r`nCachedProcessId,52,int`r`nCachedControlType,53,CONTROLTYPEID`r`nCachedLocalizedControlType,54,BSTR`r`nCachedName,55,BSTR`r`nCachedAcceleratorKey,56,BSTR`r`nCachedAccessKey,57,BSTR`r`nCachedHasKeyboardFocus,58,BOOL`r`nCachedIsKeyboardFocusable,59,BOOL`r`nCachedIsEnabled,60,BOOL`r`nCachedAutomationId,61,BSTR`r`nCachedClassName,62,BSTR`r`nCachedHelpText,63,BSTR`r`nCachedCulture,64,int`r`nCachedIsControlElement,65,BOOL`r`nCachedIsContentElement,66,BOOL`r`nCachedIsPassword,67,BOOL`r`nCachedNativeWindowHandle,68,UIA_HWND`r`nCachedItemType,69,BSTR`r`nCachedIsOffscreen,70,BOOL`r`nCachedOrientation,71,OrientationType`r`nCachedFrameworkId,72,BSTR`r`nCachedIsRequiredForForm,73,BOOL`r`nCachedItemStatus,74,BSTR`r`nCachedBoundingRectangle,75,RECT`r`nCachedLabeledBy,76,IUIAutomationElement`r`nCachedAriaRole,77,BSTR`r`nCachedAriaProperties,78,BSTR`r`nCachedIsDataValidForForm,79,BOOL`r`nCachedControllerFor,80,IUIAutomationElementArray`r`nCachedDescribedBy,81,IUIAutomationElementArray`r`nCachedFlowsTo,82,IUIAutomationElementArray`r`nCachedProviderDescription,83,BSTR&quot;
	
	SetFocus() {
		return UIA_Hr(DllCall(this.__Vt(3), &quot;ptr&quot;,this.__Value))
	}
	GetRuntimeId(ByRef stringId=&quot;&quot;) {
		return UIA_Hr(DllCall(this.__Vt(4), &quot;ptr&quot;,this.__Value, &quot;ptr*&quot;,sa))? ComObj(0x2003,sa,1):
	}
	FindFirst(c=&quot;&quot;, scope=0x2) {
		static tc	; TrueCondition
		if !tc
			tc:=this.__uia.CreateTrueCondition()
		return UIA_Hr(DllCall(this.__Vt(5), &quot;ptr&quot;,this.__Value, &quot;uint&quot;,scope, &quot;ptr&quot;,(c=&quot;&quot;?tc:c).__Value, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
	FindAll(c=&quot;&quot;, scope=0x2) {
		static tc	; TrueCondition
		if !tc
			tc:=this.__uia.CreateTrueCondition()
		return UIA_Hr(DllCall(this.__Vt(6), &quot;ptr&quot;,this.__Value, &quot;uint&quot;,scope, &quot;ptr&quot;,(c=&quot;&quot;?tc:c).__Value, &quot;ptr*&quot;,out))? UIA_ElementArray(out):
	}
	;~ Find (First/All, Element/Children/Descendants/Parent/Ancestors/Subtree, Conditions)
	;~ FindFirstBuildCache 	7	IUIAutomationElement
	;~ FindAllBuildCache 	8	IUIAutomationElementArray
	;~ BuildUpdatedCache 	9	IUIAutomationElement
	GetCurrentPropertyValue(propertyId, ByRef out=&quot;&quot;) {
		return UIA_Hr(DllCall(this.__Vt(10), &quot;ptr&quot;,this.__Value, &quot;uint&quot;,propertyId, &quot;ptr&quot;,UIA_Variant(out)))? UIA_VariantData(out):
	}
	GetCurrentPropertyValueEx(propertyId, ignoreDefaultValue=1, ByRef out=&quot;&quot;) {
	; Passing FALSE in the ignoreDefaultValue parameter is equivalent to calling GetCurrentPropertyValue
		return UIA_Hr(DllCall(this.__Vt(11), &quot;ptr&quot;,this.__Value, &quot;uint&quot;,propertyId, &quot;uint&quot;,ignoreDefaultValue, &quot;ptr&quot;,UIA_Variant(out)))? UIA_VariantData(out):
	}
	;~ GetCachedPropertyValue 	12	VARIANT
	;~ GetCachedPropertyValueEx 	13	VARIANT
	GetCurrentPatternAs(pattern=&quot;&quot;) {
		if IsObject(UIA_%pattern%Pattern)&amp;&amp;(iid:=UIA_%pattern%Pattern.__iid)&amp;&amp;(pId:=UIA_%pattern%Pattern.__PatternID)
			return UIA_Hr(DllCall(this.__Vt(14), &quot;ptr&quot;,this.__Value, &quot;int&quot;,pId, &quot;ptr&quot;,UIA_GUID(riid,iid), &quot;ptr*&quot;,out))? new UIA_%pattern%Pattern(out):
		else throw Exception(&quot;Pattern not implemented.&quot;,-1, &quot;UIA_&quot; pattern &quot;Pattern&quot;)
	}
	;~ GetCachedPatternAs 	15	void **ppv
	;~ GetCurrentPattern 	16	Iunknown **patternObject
	;~ GetCachedPattern 	17	Iunknown **patternObject
	;~ GetCachedParent 	18	IUIAutomationElement
	GetCachedChildren() { ; Haven&#039;t successfully tested
		return UIA_Hr(DllCall(this.__Vt(19), &quot;ptr&quot;,this.__Value, &quot;ptr*&quot;,out))&amp;&amp;out? UIA_ElementArray(out):
	}
	;~ GetClickablePoint 	84	POINT, BOOL
}

class UIA_ElementArray extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee671426(v=vs.85).aspx
	static __IID := &quot;{14314595-b4bc-4055-95f2-58f2e42c9855}&quot;
		,  __properties := &quot;Length,3,int&quot;
	
	GetElement(i) {
		return UIA_Hr(DllCall(this.__Vt(4), &quot;ptr&quot;,this.__Value, &quot;int&quot;,i, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
}

class UIA_TreeWalker extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee671470(v=vs.85).aspx
	static __IID := &quot;{4042c624-389c-4afc-a630-9df854a541fc}&quot;
		,  __properties := &quot;Condition,15,IUIAutomationCondition&quot;
	
	GetParentElement(e) {
		return UIA_Hr(DllCall(this.__Vt(3), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e.__Value, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
	GetFirstChildElement(e) {
		return UIA_Hr(DllCall(this.__Vt(4), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e.__Value, &quot;ptr*&quot;,out))&amp;&amp;out? new UIA_Element(out):
	}
	GetLastChildElement(e) {
		return UIA_Hr(DllCall(this.__Vt(5), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e.__Value, &quot;ptr*&quot;,out))&amp;&amp;out? new UIA_Element(out):
	}
	GetNextSiblingElement(e) {
		return UIA_Hr(DllCall(this.__Vt(6), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e.__Value, &quot;ptr*&quot;,out))&amp;&amp;out? new UIA_Element(out):
	}
	GetPreviousSiblingElement(e) {
		return UIA_Hr(DllCall(this.__Vt(7), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e.__Value, &quot;ptr*&quot;,out))&amp;&amp;out? new UIA_Element(out):
	}
	NormalizeElement(e) {
		return UIA_Hr(DllCall(this.__Vt(8), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e.__Value, &quot;ptr*&quot;,out))&amp;&amp;out? new UIA_Element(out):
	}
/*	GetParentElementBuildCache(e, cacheRequest) {
		return UIA_Hr(DllCall(this.__Vt(9), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e.__Value, &quot;ptr&quot;,cacheRequest.__Value.__Value, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
	GetFirstChildElementBuildCache(e, cacheRequest) {
		return UIA_Hr(DllCall(this.__Vt(10), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e.__Value, &quot;ptr&quot;,cacheRequest.__Value, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
	GetLastChildElementBuildCache(e, cacheRequest) {
		return UIA_Hr(DllCall(this.__Vt(11), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e.__Value, &quot;ptr&quot;,cacheRequest.__Value, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
	GetNextSiblingElementBuildCache(e, cacheRequest) {
		return UIA_Hr(DllCall(this.__Vt(12), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e.__Value, &quot;ptr&quot;,cacheRequest.__Value, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
	GetPreviousSiblingElementBuildCache(e, cacheRequest) {
		return UIA_Hr(DllCall(this.__Vt(13), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e.__Value, &quot;ptr&quot;,cacheRequest.__Value, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
	NormalizeElementBuildCache(e, cacheRequest) {
		return UIA_Hr(DllCall(this.__Vt(14), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,e.__Value, &quot;ptr&quot;,cacheRequest.__Value, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
*/
}

class UIA_Condition extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee671420(v=vs.85).aspx
	static __IID := &quot;{352ffba8-0973-437c-a61f-f64cafd81df9}&quot;
}

class UIA_PropertyCondition extends UIA_Condition {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696121(v=vs.85).aspx
	static __IID := &quot;{99ebf2cb-5578-4267-9ad4-afd6ea77e94b}&quot;
		,  __properties := &quot;PropertyId,3,PROPERTYID`r`nPropertyValue,4,VARIANT`r`nPropertyConditionFlags,5,PropertyConditionFlags&quot;
}
; should returned children have a condition type (property/and/or/bool/not), or be a generic uia_condition object?
class UIA_AndCondition extends UIA_Condition {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee671407(v=vs.85).aspx
	static __IID := &quot;{a7d0af36-b912-45fe-9855-091ddc174aec}&quot;
		,  __properties := &quot;ChildCount,3,int&quot;
	
	;~ GetChildrenAsNativeArray	4	IUIAutomationCondition ***childArray
	GetChildren() {
		return UIA_Hr(DllCall(this.__Vt(5), &quot;ptr&quot;,this.__Value, &quot;ptr*&quot;,out))&amp;&amp;out? ComObj(0x2003,out,1):
	}
}
class UIA_OrCondition extends UIA_Condition {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696108(v=vs.85).aspx
	static __IID := &quot;{8753f032-3db1-47b5-a1fc-6e34a266c712}&quot;
		,  __properties := &quot;ChildCount,3,int&quot;
	
	;~ GetChildrenAsNativeArray	4	IUIAutomationCondition ***childArray
	;~ GetChildren	5	SAFEARRAY
}
class UIA_BoolCondition extends UIA_Condition {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee671411(v=vs.85).aspx
	static __IID := &quot;{8753f032-3db1-47b5-a1fc-6e34a266c712}&quot;
		,  __properties := &quot;BooleanValue,3,boolVal&quot;
}
class UIA_NotCondition extends UIA_Condition {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696106(v=vs.85).aspx
	static __IID := &quot;{f528b657-847b-498c-8896-d52b565407a1}&quot;
	
	;~ GetChild	3	IUIAutomationCondition
}

class UIA_IUnknown extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ms680509(v=vs.85).aspx
	static __IID := &quot;{00000000-0000-0000-C000-000000000046}&quot;
}

class UIA_CacheRequest  extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee671413(v=vs.85).aspx
	static __IID := &quot;{b32a92b5-bc25-4078-9c08-d7ee95c48e03}&quot;
}


class _UIA_EventHandler {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696044(v=vs.85).aspx
	static __IID := &quot;{146c3c17-f12e-4e22-8c27-f894b9b79c69}&quot;
	
/*	HandleAutomationEvent	3
		[in]  IUIAutomationElement *sender,
		[in]  EVENTID eventId
*/
}
class _UIA_FocusChangedEventHandler {		
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696051(v=vs.85).aspx
	static __IID := &quot;{c270f6b5-5c69-4290-9745-7a7f97169468}&quot;
	
/*	HandleFocusChangedEvent	3
		[in]  IUIAutomationElement *sender
*/
}
class _UIA_PropertyChangedEventHandler {		
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696119(v=vs.85).aspx
	static __IID := &quot;{40cd37d4-c756-4b0c-8c6f-bddfeeb13b50}&quot;
	
/*	HandlePropertyChangedEvent	3
		[in]  IUIAutomationElement *sender,
		[in]  PROPERTYID propertyId,
		[in]  VARIANT newValue
*/
}
class _UIA_StructureChangedEventHandler {		
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696197(v=vs.85).aspx
	static __IID := &quot;{e81d1b4e-11c5-42f8-9754-e7036c79f054}&quot;
	
/*	HandleStructureChangedEvent	3
		[in]  IUIAutomationElement *sender,
		[in]  StructureChangeType changeType,
		[in]  SAFEARRAY *runtimeId[int]
*/
}
class _UIA_TextEditTextChangedEventHandler { ; Windows 8.1 Preview [desktop apps only]
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/dn302202(v=vs.85).aspx
	static __IID := &quot;{92FAA680-E704-4156-931A-E32D5BB38F3F}&quot;
	
	;~ HandleTextEditTextChangedEvent	3
}


;~ 		UIA_Patterns - http://msdn.microsoft.com/en-us/library/windows/desktop/ee684023
class UIA_DockPattern extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee671421
	static	__IID := &quot;{fde5ef97-1464-48f6-90bf-43d0948e86ec}&quot;
		,	__PatternID := 10011
		,	__Properties := &quot;CurrentDockPosition,4,int`r`nCachedDockPosition,5,int&quot;

	SetDockPosition(Pos) {
		return UIA_Hr(DllCall(this.__Vt(3), &quot;ptr&quot;,this.__Value, &quot;uint&quot;,pos))
	}
/*	DockPosition_Top	= 0,
	DockPosition_Left	= 1,
	DockPosition_Bottom	= 2,
	DockPosition_Right	= 3,
	DockPosition_Fill	= 4,
	DockPosition_None	= 5
*/
}
class UIA_ExpandCollapsePattern extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696046
	static	__IID := &quot;{619be086-1f4e-4ee4-bafa-210128738730}&quot;
		,	__PatternID := 10005
		,	__Properties := &quot;CachedExpandCollapseState,6,int`r`nCurrentExpandCollapseState,5,int&quot;
	
	Expand() {
		return UIA_Hr(DllCall(this.__Vt(3), &quot;ptr&quot;,this.__Value))
	}
	Collapse() {
		return UIA_Hr(DllCall(this.__Vt(4), &quot;ptr&quot;,this.__Value))
	}	
/*	ExpandCollapseState_Collapsed	= 0,
	ExpandCollapseState_Expanded	= 1,
	ExpandCollapseState_PartiallyExpanded	= 2,
	ExpandCollapseState_LeafNode	= 3
*/
}
class UIA_GridItemPattern extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696053
	static	__IID := &quot;{78f8ef57-66c3-4e09-bd7c-e79b2004894d}&quot;
		,	__PatternID := 10007
		,	__Properties := &quot;CurrentContainingGrid,3,IUIAutomationElement`r`nCurrentRow,4,int`r`nCurrentColumn,5,int`r`nCurrentRowSpan,6,int`r`nCurrentColumnSpan,7,int`r`nCachedContainingGrid,8,IUIAutomationElement`r`nCachedRow,9,int`r`nCachedColumn,10,int`r`nCachedRowSpan,11,int`r`nCachedColumnSpan,12,int&quot;
}
class UIA_GridPattern extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696064
	static	__IID := &quot;{414c3cdc-856b-4f5b-8538-3131c6302550}&quot;
		,	__PatternID := 10006
		,	__Properties := &quot;CurrentRowCount,4,int`r`nCurrentColumnCount,5,int`r`nCachedRowCount,6,int`r`nCachedColumnCount,7,int&quot;

	GetItem(row,column) { ; Hr!=0 if no result, or blank output?
		return UIA_Hr(DllCall(this.__Vt(3), &quot;ptr&quot;,this.__Value, &quot;uint&quot;,row, &quot;uint&quot;,column, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
}
class UIA_InvokePattern extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696070
	static	__IID := &quot;{fb377fbe-8ea6-46d5-9c73-6499642d3059}&quot;
		,	__PatternID := 10000
	
	Invoke() {
		return UIA_Hr(DllCall(this.__Vt(3), &quot;ptr&quot;,this.__Value))
	}
}
class UIA_ItemContainerPattern extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696072
	static	__IID := &quot;{c690fdb2-27a8-423c-812d-429773c9084e}&quot;
		,	__PatternID := 10019

	FindItemByProperty(startAfter, propertyId, ByRef value, type=8) {	; Hr!=0 if no result, or blank output?
		if (type!=&quot;Variant&quot;)
			UIA_Variant(value,type,value)
		return UIA_Hr(DllCall(this.__Vt(3), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,startAfter.__Value, &quot;int&quot;,propertyId, &quot;ptr&quot;,&amp;value, &quot;ptr*&quot;,out))? new UIA_Element(out):
	}
}
class UIA_LegacyIAccessiblePattern extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696074
	static	__IID := &quot;{828055ad-355b-4435-86d5-3b51c14a9b1b}&quot;
		,	__PatternID := 10018
		,	__Properties := &quot;CurrentChildId,6,int`r`nCurrentName,7,BSTR`r`nCurrentValue,8,BSTR`r`nCurrentDescription,9,BSTR`r`nCurrentRole,10,DWORD`r`nCurrentState,11,DWORD`r`nCurrentHelp,12,BSTR`r`nCurrentKeyboardShortcut,13,BSTR`r`nCurrentDefaultAction,15,BSTR`r`nCachedChildId,16,int`r`nCachedName,17,BSTR`r`nCachedValue,18,BSTR`r`nCachedDescription,19,BSTR`r`nCachedRole,20,DWORD`r`nCachedState,21,DWORD`r`nCachedHelp,22,BSTR`r`nCachedKeyboardShortcut,23,BSTR`r`nCachedDefaultAction,25,BSTR&quot;

	Select(flags=3) {
		return UIA_Hr(DllCall(this.__Vt(3), &quot;ptr&quot;,this.__Value, &quot;int&quot;,flags))
	}
	DoDefaultAction() {
		return UIA_Hr(DllCall(this.__Vt(4), &quot;ptr&quot;,this.__Value))
	}
	SetValue(value) {
		return UIA_Hr(DllCall(this.__Vt(5), &quot;ptr&quot;,this.__Value, &quot;ptr&quot;,&amp;value))
	}
	GetCurrentSelection() { ; Not correct
		;~ if (hr:=DllCall(this.__Vt(14), &quot;ptr&quot;,this.__Value, &quot;ptr*&quot;,array))=0
			;~ return new UIA_ElementArray(array)
		;~ else
			;~ MsgBox,, Error, %hr%
	}
	;~ GetCachedSelection	24	IUIAutomationElementArray
	GetIAccessible() {
	/*	This method returns NULL if the underlying implementation of the UI Automation element is not a native 
	Microsoft Active Accessibility server; that is, if a client attempts to retrieve the IAccessible interface 
	for an element originally supported by a proxy object from OLEACC.dll, or by the UIA-to-MSAA Bridge.
	*/
		return UIA_Hr(DllCall(this.__Vt(26), &quot;ptr&quot;,this.__Value, &quot;ptr*&quot;,pacc))&amp;&amp;pacc? ComObj(9,pacc,1):
	}
}
class UIA_MultipleViewPattern extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696099
	static	__IID := &quot;{8d253c91-1dc5-4bb5-b18f-ade16fa495e8}&quot;
		,	__PatternID := 10008
		,	__Properties := &quot;CurrentCurrentView,5,int`r`nCachedCurrentView,7,int&quot;

	GetViewName(view) { ; need to release BSTR?
		return UIA_Hr(DllCall(this.__Vt(3), &quot;ptr&quot;,this.__Value, &quot;int&quot;,view, &quot;ptr*&quot;,name))? StrGet(name):
	}
	SetCurrentView(view) {
		return UIA_Hr(DllCall(this.__Vt(4), &quot;ptr&quot;,this.__Value, &quot;int&quot;,view))
	}
	GetCurrentSupportedViews() {
		return UIA_Hr(DllCall(this.__Vt(6), &quot;ptr&quot;,this.__Value, &quot;ptr*&quot;,out))? ComObj(0x2003,out,1):
	}
	GetCachedSupportedViews() {
		return UIA_Hr(DllCall(this.__Vt(8), &quot;ptr&quot;,this.__Value, &quot;ptr*&quot;,out))? ComObj(0x2003,out,1):
	}
}
class UIA_RangeValuePattern extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696147
	static	__IID := &quot;{59213f4f-7346-49e5-b120-80555987a148}&quot;
		,	__PatternID := 10003
		,	__Properties := &quot;CurrentValue,4,double`r`nCurrentIsReadOnly,5,BOOL`r`nCurrentMaximum,6,double`r`nCurrentMinimum,7,double`r`nCurrentLargeChange,8,double`r`nCurrentSmallChange,9,double`r`nCachedValue,10,double`r`nCachedIsReadOnly,11,BOOL`r`nCachedMaximum,12,double`r`nCachedMinimum,13,double`r`nCachedLargeChange,14,double`r`nCachedSmallChange,15,double&quot;

	SetValue(val) {
		return UIA_Hr(DllCall(this.__Vt(3), &quot;ptr&quot;,this.__Value, &quot;double&quot;,val))
	}
}
class UIA_ScrollItemPattern extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696165
	static	__IID := &quot;{b488300f-d015-4f19-9c29-bb595e3645ef}&quot;
		,	__PatternID := 10017

	ScrollIntoView() {
		return UIA_Hr(DllCall(this.__Vt(3), &quot;ptr&quot;,this.__Value))
	}
}
class UIA_ScrollPattern extends UIA_Base {
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/ee696167
	static	__IID := &quot;{88f4d42a-e881-459d-a77c-73bbbb7e02dc}&quot;
		,	__PatternID := 10004
		,	__Properties := &quot;CurrentHorizontalScrollPercent,5,double`r`nCurrentVerticalScrollPercent,6,double`r`nCurrentHorizontalViewSize,7,double`r`CurrentHorizontallyScrollable,9,BOOL`r`nCurrentVerticallyScrollable,10,BOOL`r`nCachedHorizontalScrollPercent,11,double`r`nCachedVerticalScrollPercent,12,double`r`nCachedHorizontalViewSize,13,double`r`nCachedVerticalViewSize,14,double`r`nCachedHorizontallyScrollable,15,BOOL`r`nCachedVerticallyScrollable,16,BOOL&quot;
		
	Scroll(horizontal, vertical) {
		return UIA_Hr(DllCall(this.__Vt(3), &quot;ptr&quot;,this.__Value, &quot;uint&quot;,horizontal, &quot;uint&quot;,vertical))
	}
	SetScrollPercent(horizontal, vertical) {
		return UIA_Hr(DllCall(this.__Vt(4), &quot;ptr&quot;,this.__Value, &quot;double&quot;,horizontal, &quot;double&quot;,vertical))
	}
/*	UIA_ScrollPatternNoScroll	=	-1
	ScrollAmount_LargeDecrement	= 0,
	ScrollAmount_SmallDecrement	= 1,
	ScrollAmount_NoAmount	= 2,
	ScrollAmount_LargeIncrement	= 3,
	ScrollAmount_SmallIncrement	= 4
*/
}
;~ class UIA_SelectionItemPattern extends UIA_Base {10010
;~ class UIA_SelectionPattern extends UIA_Base {10001
;~ class UIA_SpreadsheetItemPattern extends UIA_Base {10027
;~ class UIA_SpreadsheetPattern extends UIA_Base {10026
;~ class UIA_StylesPattern extends UIA_Base {10025
;~ class UIA_SynchronizedInputPattern extends UIA_Base {10021
;~ class UIA_TableItemPattern extends UIA_Base {10013
;~ class UIA_TablePattern extends UIA_Base {10012
;~ class UIA_TextChildPattern extends UIA_Base {10029
;~ class UIA_TextEditPattern extends UIA_Base {10032
;~ class UIA_TextPattern extends UIA_Base {10014
;~ class UIA_TextPattern2 extends UIA_Base {10024
;~ class UIA_TogglePattern extends UIA_Base {10015
;~ class UIA_TransformPattern extends UIA_Base {10016
;~ class UIA_TransformPattern2 extends UIA_Base {10028
;~ class UIA_ValuePattern extends UIA_Base {10002
;~ class UIA_VirtualizedItemPattern extends UIA_Base {10020
;~ class UIA_WindowPattern extends UIA_Base {10009
;~ class UIA_AnnotationPattern extends UIA_Base {10023		; Windows 8 [desktop apps only]
;~ class UIA_DragPattern extends UIA_Base {10030			; Windows 8 [desktop apps only]
;~ class UIA_DropTargetPattern extends UIA_Base {10031		; Windows 8 [desktop apps only]
/* class UIA_ObjectModelPattern extends UIA_Base {			; Windows 8 [desktop apps only]
	;~ http://msdn.microsoft.com/en-us/library/windows/desktop/hh437262(v=vs.85).aspx
	static	__IID := &quot;{71c284b3-c14d-4d14-981e-19751b0d756d}&quot;
		,	__PatternID := 10022
	
	GetUnderlyingObjectModel() {
		return UIA_Hr(DllCall(this.__Vt(3), &quot;ptr&quot;,this.__Value))
	}
}
*/

;~ class UIA_PatternHandler extends UIA_Base {
;~ class UIA_PatternInstance extends UIA_Base {
;~ class UIA_TextRange extends UIA_Base {
;~ class UIA_TextRange2 extends UIA_Base {
;~ class UIA_TextRangeArray extends UIA_Base {




{  ;~ UIA Functions
	UIA_Interface() {
		try {
			if uia:=ComObjCreate(&quot;{ff48dba4-60ef-4201-aa87-54103eef594e}&quot;,&quot;{30cbe57d-d9d0-452a-ab13-7ac5ac4825ee}&quot;)
				return uia:=new UIA_Interface(uia), uia.base.base.__UIA:=uia
			throw &quot;UIAutomation Interface failed to initialize.&quot;
		} catch e
			MsgBox, 262160, UIA Startup Error, % IsObject(e)?&quot;IUIAutomation Interface is not registered.&quot;:e.Message
	}
	UIA_Hr(hr) {
		;~ http://blogs.msdn.com/b/eldar/archive/2007/04/03/a-lot-of-hresult-codes.aspx
		static err:={0x8000FFFF:&quot;Catastrophic failure.&quot;,0x80004001:&quot;Not implemented.&quot;,0x8007000E:&quot;Out of memory.&quot;,0x80070057:&quot;One or more arguments are not valid.&quot;,0x80004002:&quot;Interface not supported.&quot;,0x80004003:&quot;Pointer not valid.&quot;,0x80070006:&quot;Handle not valid.&quot;,0x80004004:&quot;Operation aborted.&quot;,0x80004005:&quot;Unspecified error.&quot;,0x80070005:&quot;General access denied.&quot;,0x800401E5:&quot;The object identified by this moniker could not be found.&quot;,0x80040201:&quot;UIA_E_ELEMENTNOTAVAILABLE&quot;,0x80040200:&quot;UIA_E_ELEMENTNOTENABLED&quot;,0x80131509:&quot;UIA_E_INVALIDOPERATION&quot;,0x80040202:&quot;UIA_E_NOCLICKABLEPOINT&quot;,0x80040204:&quot;UIA_E_NOTSUPPORTED&quot;,0x80040203:&quot;UIA_E_PROXYASSEMBLYNOTLOADED&quot;} ; //not completed
		if hr&amp;&amp;(hr&amp;=0xFFFFFFFF) {
			RegExMatch(Exception(&quot;&quot;,-2).what,&quot;(\w+).(\w+)&quot;,i)
			throw Exception(UIA_Hex(hr) &quot; - &quot; err[hr], -2, i2 &quot;  (&quot; i1 &quot;)&quot;)
		}
		return !hr
	}
	UIA_NotImplemented() {
		RegExMatch(Exception(&quot;&quot;,-2).What,&quot;(\D+)\.(\D+)&quot;,m)
		MsgBox, 262192, UIA Message, Class:`t%m1%`nMember:`t%m2%`n`nMethod has not been implemented yet.
	}
	UIA_ElementArray(p, uia=&quot;&quot;) { ; should AHK Object be 0 or 1 based?
		a:=new UIA_ElementArray(p),out:=[]
		Loop % a.Length
			out[A_Index]:=a.GetElement(A_Index-1)
		return out, out.base:={UIA_ElementArray:a}
	}
	UIA_RectToObject(ByRef r) { ; rect.__Value work with DllCalls?
		static b:={__Class:&quot;object&quot;,__Type:&quot;RECT&quot;,Struct:Func(&quot;UIA_RectStructure&quot;)}
		return {l:NumGet(r,0,&quot;Int&quot;),t:NumGet(r,4,&quot;Int&quot;),r:NumGet(r,8,&quot;Int&quot;),b:NumGet(r,12,&quot;Int&quot;),base:b}
	}
	UIA_RectStructure(this, ByRef r) {
		static sides:=&quot;ltrb&quot;
		VarSetCapacity(r,16)
		Loop Parse, sides
			NumPut(this[A_LoopField],r,(A_Index-1)*4,&quot;Int&quot;)
	}
	UIA_SafeArraysToObject(keys,values) {
	;~	1 dim safearrays w/ same # of elements
		out:={}
		for key in keys
			out[key]:=values[A_Index-1]
		return out
	}
	UIA_Hex(p) {
		setting:=A_FormatInteger
		SetFormat,IntegerFast,H
		out:=p+0 &quot;&quot;
		SetFormat,IntegerFast,%setting%
		return out
	}
	UIA_GUID(ByRef GUID, sGUID) { ;~ Converts a string to a binary GUID and returns its address.
		VarSetCapacity(GUID,16,0)
		return DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;wstr&quot;,sGUID, &quot;ptr&quot;,&amp;GUID)&gt;=0?&amp;GUID:&quot;&quot;
	}
	UIA_Variant(ByRef var,type=0,val=0) {
		; Does a variant need to be cleared? If it uses SysAllocString? 
		return (VarSetCapacity(var,8+2*A_PtrSize)+NumPut(type,var,0,&quot;short&quot;)+NumPut(type=8? DllCall(&quot;oleaut32\SysAllocString&quot;, &quot;ptr&quot;,&amp;val):val,var,8,&quot;ptr&quot;))*0+&amp;var
	}
	UIA_IsVariant(ByRef vt, ByRef type=&quot;&quot;) {
		size:=VarSetCapacity(vt),type:=NumGet(vt,&quot;UShort&quot;)
		return size&gt;=16&amp;&amp;size&lt;=24&amp;&amp;type&gt;=0&amp;&amp;(type&lt;=23||type|0x2000)
	}
	UIA_Type(ByRef item, ByRef info) {
	}
	UIA_VariantData(ByRef p, flag=1) {
		; based on Sean&#039;s COM_Enumerate function
		; need to clear varaint? what if you still need it (flag param)?
		return !UIA_IsVariant(p,vt)?&quot;Invalid Variant&quot;
				:vt=3?NumGet(p,8,&quot;int&quot;)
				:vt=8?StrGet(NumGet(p,8))
				:vt=9||vt=13||vt&amp;0x2000?ComObj(vt,NumGet(p,8),flag)
				:vt&lt;0x1000&amp;&amp;UIA_VariantChangeType(&amp;p,&amp;p)=0?StrGet(NumGet(p,8)) UIA_VariantClear(&amp;p)
				:NumGet(p,8)
	/*
		VT_EMPTY     =      0  		; No value
		VT_NULL      =      1 		; SQL-style Null
		VT_I2        =      2 		; 16-bit signed int
		VT_I4        =      3 		; 32-bit signed int
		VT_R4        =      4 		; 32-bit floating-point number
		VT_R8        =      5 		; 64-bit floating-point number
		VT_CY        =      6 		; Currency
		VT_DATE      =      7  		; Date
		VT_BSTR      =      8 		; COM string (Unicode string with length prefix)
		VT_DISPATCH  =      9 		; COM object 
		VT_ERROR     =    0xA  10	; Error code (32-bit integer)
		VT_BOOL      =    0xB  11	; Boolean True (-1) or False (0)
		VT_VARIANT   =    0xC  12	; VARIANT (must be combined with VT_ARRAY or VT_BYREF)
		VT_UNKNOWN   =    0xD  13	; IUnknown interface pointer
		VT_DECIMAL   =    0xE  14	; (not supported)
		VT_I1        =   0x10  16	; 8-bit signed int
		VT_UI1       =   0x11  17	; 8-bit unsigned int
		VT_UI2       =   0x12  18	; 16-bit unsigned int
		VT_UI4       =   0x13  19	; 32-bit unsigned int
		VT_I8        =   0x14  20	; 64-bit signed int
		VT_UI8       =   0x15  21	; 64-bit unsigned int
		VT_INT       =   0x16  22	; Signed machine int
		VT_UINT      =   0x17  23	; Unsigned machine int
		VT_RECORD    =   0x24  36	; User-defined type
		VT_ARRAY     = 0x2000  		; SAFEARRAY
		VT_BYREF     = 0x4000  		; Pointer to another type of value
					 = 0x1000  4096
		COM_VariantChangeType(pvarDst, pvarSrc, vt=8) {
			return DllCall(&quot;oleaut32\VariantChangeTypeEx&quot;, &quot;ptr&quot;,pvarDst, &quot;ptr&quot;,pvarSrc, &quot;Uint&quot;,1024, &quot;Ushort&quot;,0, &quot;Ushort&quot;,vt)
		}
		COM_VariantClear(pvar) {
			DllCall(&quot;oleaut32\VariantClear&quot;, &quot;ptr&quot;,pvar)
		}
		COM_SysAllocString(str) {
			Return	DllCall(&quot;oleaut32\SysAllocString&quot;, &quot;Uint&quot;, &amp;str)
		}
		COM_SysFreeString(pstr) {
				DllCall(&quot;oleaut32\SysFreeString&quot;, &quot;Uint&quot;, pstr)
		}
		COM_SysString(ByRef wString, sString) {
			VarSetCapacity(wString,4+nLen:=2*StrLen(sString))
			Return	DllCall(&quot;kernel32\lstrcpyW&quot;,&quot;Uint&quot;,NumPut(nLen,wString),&quot;Uint&quot;,&amp;sString)
		}
	*/
	}
	UIA_VariantChangeType(pvarDst, pvarSrc, vt=8) { ; written by Sean
		return DllCall(&quot;oleaut32\VariantChangeTypeEx&quot;, &quot;ptr&quot;,pvarDst, &quot;ptr&quot;,pvarSrc, &quot;Uint&quot;,1024, &quot;Ushort&quot;,0, &quot;Ushort&quot;,vt)
	}
	UIA_VariantClear(pvar) { ; Written by Sean
		DllCall(&quot;oleaut32\VariantClear&quot;, &quot;ptr&quot;,pvar)
	}
}
MsgBox(msg) {
	MsgBox %msg%
}

/*
enum TreeScope
    {	TreeScope_Element	= 0x1,
	TreeScope_Children	= 0x2,
	TreeScope_Descendants	= 0x4,
	TreeScope_Parent	= 0x8,
	TreeScope_Ancestors	= 0x10,
	TreeScope_Subtree	= ( ( TreeScope_Element | TreeScope_Children )  | TreeScope_Descendants ) 
    } ;
DllCall(&quot;oleaut32\SafeArrayGetVartype&quot;, &quot;ptr*&quot;,ComObjValue(SafeArray), &quot;uint*&quot;,pvt)
HRESULT SafeArrayGetVartype(
  _In_   SAFEARRAY *psa,
  _Out_  VARTYPE *pvt
);
DllCall(&quot;oleaut32\SafeArrayDestroy&quot;, &quot;ptr&quot;,ComObjValue(SafeArray))
HRESULT SafeArrayDestroy(
  _In_  SAFEARRAY *psa
);</code></pre></div><p>Или проще:<br /></p><div class="codebox"><pre><code>F11::MsgBox, % GetLayout()

GetLayout()
{
   hwnd := WinExist(&quot;A&quot;)
   ControlGetFocus, FocusedControl, ahk_id %hwnd%
   if (FocusedControl != &quot;Windows.UI.Core.CoreWindow1&quot;)
      hwnd := WinExist(&quot;ahk_exe MicrosoftEdgeCP.exe&quot;)
   ControlGet, Hwnd, Hwnd,, %FocusedControl%, ahk_id %hwnd%
   ThreadID := DllCall(&quot;GetWindowThreadProcessId&quot;, Ptr, hWnd, UInt, 0, Ptr)
   InputLocaleID := DllCall(&quot;GetKeyboardLayout&quot;, Ptr, ThreadID, Ptr)
   Return (InputLocaleID &amp; 0xFFFF = 0x409) ? &quot;En&quot; : &quot;Ru&quot;
}</code></pre></div><p>Или общий вариант с проверкой сфокусированного контрола на привязку к процессу ApplicationFrameHost.exe:<br />(У меня вроде язык верно определяет, хотя, возможно, определение истинного процесса через UIA надёжней будет.)<br /></p><div class="codebox"><pre><code>F11::MsgBox, % GetLayout()

GetLayout()
{
   WindowHwnd := WinExist(&quot;A&quot;)
   ControlGetFocus, FocusedControl, ahk_id %WindowHwnd%
   ControlGet, Hwnd, Hwnd,, %FocusedControl%, ahk_id %WindowHwnd%
   WinGet, processname, processname, ahk_id %hwnd%
   if (processname = &quot;ApplicationFrameHost.exe&quot;)
   {
      WinGet, list, list
      loop % list
      {
         if (list%A_Index% = WindowHwnd)
         {
            n := A_Index - 1, WindowHwnd := list%n%
            ControlGetFocus, FocusedControl, ahk_id %WindowHwnd%
            ControlGet, Hwnd, Hwnd,, %FocusedControl%, ahk_id %WindowHwnd%
            break
         }
      }
   }
   ThreadID := DllCall(&quot;GetWindowThreadProcessId&quot;, Ptr, hWnd, UInt, 0, Ptr)
   InputLocaleID := DllCall(&quot;GetKeyboardLayout&quot;, Ptr, ThreadID, Ptr)
   Return (InputLocaleID &amp; 0xFFFF = 0x409) ? &quot;En&quot; : &quot;Ru&quot;
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-08-15T16:54:12Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127982#p127982</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127981#p127981" />
			<content type="html"><![CDATA[<p>А почему бы контролам не принадлежать процессу ApplicationFrameHost.exe, если всё окно принадлежит ему? Во всяком случае, так определяется через Process Hacker. Он же показывает, что у процесса MicrosoftEdge.exe своего окна нет.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2018-08-15T16:30:40Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127981#p127981</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127977#p127977" />
			<content type="html"><![CDATA[<p>Вроде понял причину.<br />У Edge почему-то контролы через ControlGet определяются, как относящиеся к процессу Application Frame Host, а не к процессу самого Edge.<br />Можно определить их принадлежность к Edge через свойство processId UI интерфейса.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-08-15T14:41:59Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127977#p127977</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127961#p127961" />
			<content type="html"><![CDATA[<p>Этот код у меня в Edge всегда английский показывает.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2018-08-15T10:57:55Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127961#p127961</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127957#p127957" />
			<content type="html"><![CDATA[<p>Поэтому думаю правильней определять так:<br /></p><div class="codebox"><pre><code>F11::MsgBox, % GetLayout()

GetLayout()
{
   WindowHwnd := WinExist(&quot;A&quot;)
   ControlGetFocus, FocusedControl, ahk_id %WindowHwnd%
   ControlGet, Hwnd, Hwnd,, %FocusedControl%, ahk_id %WindowHwnd%
   ThreadID := DllCall(&quot;GetWindowThreadProcessId&quot;, Ptr, hWnd, UInt, 0, Ptr)
   InputLocaleID := DllCall(&quot;GetKeyboardLayout&quot;, Ptr, ThreadID, Ptr)
   Return (InputLocaleID &amp; 0xFFFF = 0x409) ? &quot;En&quot; : &quot;Ru&quot;
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-08-15T09:19:01Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127957#p127957</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127922#p127922" />
			<content type="html"><![CDATA[<p>Что у IE, что у Edge, каждый tab - это новый процесс.<br />А скрипт получает окно главного процесса, поэтому и не работает (на win7 тоже).</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2018-08-14T07:17:34Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127922#p127922</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127918#p127918" />
			<content type="html"><![CDATA[<p>Добавил &quot;uint&quot;. Похоже, лучше взять за правило всегда указывать возвращаемый тип. Про Висту пока неясно. Вчера я читал, что conhost там есть. Правда, что работает с ошибками. Но что имеется в виду, не пояснялось.</p><p>Edge почему-то всегда русский показывает. Наверно, опять не то окно.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2018-08-14T03:07:16Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127918#p127918</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127898#p127898" />
			<content type="html"><![CDATA[<p>Лучше так: <em>Return Format(&quot;{:#x}&quot;, DllCall(&quot;GetKeyboardLayout&quot;, &quot;uint&quot;, idThread, <strong>&quot;uint&quot;</strong>))</em>, иначе у меня на модифицированной русской раскладке выдаёт 0xfffffffff0c00419. Почему-то не определяется в Microsoft Edge, даже от администратора.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2018-08-13T17:29:52Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127898#p127898</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127897#p127897" />
			<content type="html"><![CDATA[<p>На 7-ке тоже так работает. Значит, исключение нужно только для ХР, там не пашет.<br /></p><div class="codebox"><pre><code>
F11:: MsgBox, % GetKeyboardLayout(&quot;A&quot;)

GetKeyboardLayout(Window)
{
    static GW_HWNDPREV := 3
    If (!(Window := WinExist(Window))) {
        Return 0
    }
    WinGetClass, WindowClass
    If (WindowClass = &quot;ConsoleWindowClass&quot;) {
        If (A_OSVersion = &quot;WIN_XP&quot;) {           
            WinGet, pidConsole, PID
            DllCall(&quot;AttachConsole&quot;, &quot;uint&quot;, pidConsole)
            VarSetCapacity(buff, 16)
            DllCall(&quot;GetConsoleKeyboardLayoutName&quot;, &quot;ptr&quot;, &amp;buff)
            DllCall(&quot;FreeConsole&quot;)
            Return &quot;0x&quot; . StrGet(&amp;buff)
        }
        Window := DllCall(&quot;GetWindow&quot;, &quot;ptr&quot;, Window, &quot;uint&quot;, GW_HWNDPREV, &quot;ptr&quot;)
    }
    idThread := DllCall(&quot;GetWindowThreadProcessId&quot;, &quot;ptr&quot;, Window, &quot;ptr&quot;, 0, &quot;uint&quot;)
    Return Format(&quot;{:#x}&quot;, DllCall(&quot;GetKeyboardLayout&quot;, &quot;uint&quot;, idThread, &quot;uint&quot;))
}
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2018-08-13T17:13:17Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127897#p127897</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127881#p127881" />
			<content type="html"><![CDATA[<p>Такой тоже работает.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2018-08-13T15:18:56Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127881#p127881</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127871#p127871" />
			<content type="html"><![CDATA[<p>Гут. А такой код у тебя работает для консоли?<br /></p><div class="codebox"><pre><code>
F11::
    hwndCmd := WinExist(&quot;A&quot;)
    hwndHost := DllCall(&quot;GetWindow&quot;, &quot;ptr&quot;, hwndCmd, &quot;uint&quot;, GW_HWNDPREV := 3, &quot;ptr&quot;)
    idThread := DllCall(&quot;GetWindowThreadProcessId&quot;, &quot;ptr&quot;, hwndHost, &quot;ptr&quot;, 0)
    idLang := DllCall(&quot;GetKeyboardLayout&quot;, &quot;uint&quot;, idThread, &quot;uint&quot;)
    MsgBox, % Format(&quot;{:#x}&quot;, idLang &amp; 0x3FFF)
    Return
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2018-08-13T14:42:59Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127871#p127871</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127867#p127867" />
			<content type="html"><![CDATA[<p>Вот с выбором соответствия на случай неактивного окна:<br /></p><div class="codebox"><pre><code>F11:: MsgBox % GetInputLangName(GetInputLangID(&quot;A&quot;))
 
GetInputLangID(window)  {
   if !hWnd := WinExist(window)
      return

   WinGetClass, winClass
   if (winClass != &quot;ConsoleWindowClass&quot;) || (b := SubStr(A_OSVersion, 1, 2) = &quot;10&quot;)  {
      if b  {
         WinGet, consolePID, PID
         childConhostPID := GetCmdChildConhostPID(consolePID)
         dhw_prev := A_DetectHiddenWindows
         DetectHiddenWindows, On
         hWnd := WinExist(&quot;ahk_pid &quot; . childConhostPID)
         DetectHiddenWindows, % dhw_prev
      }
      threadId := DllCall(&quot;GetWindowThreadProcessId&quot;, Ptr, hWnd, UInt, 0)
      lyt := DllCall(&quot;GetKeyboardLayout&quot;, Ptr, threadId, UInt)
      langID := Format(&quot;{:#x}&quot;, lyt &amp; 0x3FFF)
   }
   else  {
      WinGet, consolePID, PID
      DllCall(&quot;AttachConsole&quot;, Ptr, consolePID)
      VarSetCapacity(lyt, 16)
      DllCall(&quot;GetConsoleKeyboardLayoutName&quot;, Str, lyt)
      DllCall(&quot;FreeConsole&quot;)
      langID := &quot;0x&quot; . SubStr(lyt, -4)
   }
   return langID
}

GetCmdChildConhostPID(CmdPID)  {
   static TH32CS_SNAPPROCESS := 0x2, MAX_PATH := 260
   
   h := DllCall(&quot;CreateToolhelp32Snapshot&quot;, UInt, TH32CS_SNAPPROCESS, UInt, 0, Ptr)
   VarSetCapacity(PROCESSENTRY32, size := 4*7 + A_PtrSize*2 + (MAX_PATH &lt;&lt; !!A_IsUnicode), 0)
   NumPut(size, PROCESSENTRY32, &quot;UInt&quot;)
   res := DllCall(&quot;Process32First&quot;, Ptr, h, Ptr, &amp;PROCESSENTRY32)
   while res  {
      parentPid := NumGet(PROCESSENTRY32, 4*4 + A_PtrSize*2, &quot;UInt&quot;)
      if (parentPid = CmdPID)  {
         exeName := StrGet(&amp;PROCESSENTRY32 + 4*7 + A_PtrSize*2, &quot;CP0&quot;)
         if (exeName = &quot;conhost.exe&quot; &amp;&amp; PID := NumGet(PROCESSENTRY32, 4*2, &quot;UInt&quot;))
            break
      }
      res := DllCall(&quot;Process32Next&quot;, Ptr, h, Ptr, &amp;PROCESSENTRY32)
   }
   DllCall(&quot;CloseHandle&quot;, Ptr, h)
   Return PID
}
 
GetInputLangName(langId)  {
   static LOCALE_SENGLANGUAGE := 0x1001
   charCount := DllCall(&quot;GetLocaleInfo&quot;, UInt, langId, UInt, LOCALE_SENGLANGUAGE, UInt, 0, UInt, 0)
   VarSetCapacity(localeSig, size := charCount &lt;&lt; !!A_IsUnicode, 0)
   DllCall(&quot;GetLocaleInfo&quot;, UInt, langId, UInt, LOCALE_SENGLANGUAGE, Str, localeSig, UInt, size)
   return localeSig
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2018-08-13T12:43:00Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127867#p127867</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127861#p127861" />
			<content type="html"><![CDATA[<p>По моим тестам похоже, что не нужно. По крайней мере, если речь об активном окне. Видимо, при его смене расположение окон conhost в Z-order тоже меняется.</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2018-08-13T06:33:09Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127861#p127861</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127860#p127860" />
			<content type="html"><![CDATA[<p>А если запущено &gt;1 окна консоли, не нужно ли определять соответствие между conhost.exe и cmd.exe?</p>]]></content>
			<author>
				<name><![CDATA[stealzy]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=31937</uri>
			</author>
			<updated>2018-08-13T06:28:37Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127860#p127860</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: переменная раскладки клавиатуры]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=127858#p127858" />
			<content type="html"><![CDATA[<p>Да, так работает, спасибо!</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2018-08-13T03:39:52Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=127858#p127858</id>
		</entry>
</feed>
