vanheartnet

Get Text Tool

Aug 11th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. #SingleInstance,force
  2. #InstallKeybdHook
  3. ;#NoTrayIcon
  4. intro:="
  5. (
  6. The script is written by nepter, administrator of <a href=""http://bbs.ahk8.com"">Chinese autohotkey forum</a>.
  7.  
  8. Function: Press a hotkey, Capslock as default, to retrieve text under cursor and show it. It could get text in gui, html, instant messager and etc. The original Capslock is replaced by Shift+Capslock. A tray icon in notification area could change the hotkey.
  9.  
  10. You have to run it above WinXp sp3 and by Autohotkey_L
  11.  
  12. Version: ScreenReader 0.1.1a
  13. )"
  14. menu,tray,NoStandard
  15. menu,tray,add,Hotkey,hotkey
  16. menu,tray,add,About...,about
  17. menu,tray,add,Exit,exit
  18. CoordMode,mouse,screen
  19. KeyName:="capslock"
  20. Hotkey,%KeyName%,main
  21. if !uia:=ComObjCreate("{ff48dba4-60ef-4201-aa87-54103eef594e}","{30cbe57d-d9d0-452a-ab13-7ac5ac4825ee}"){
  22. msgbox UI Automation Failed.
  23. ExitApp
  24. }
  25. return
  26. +CapsLock::CapsLock
  27. exit:
  28. exitapp
  29. hotkey:
  30. gui,1:Destroy
  31. gui,1:add,text,,New Hotkey
  32. gui,1:add,Hotkey,vChosenHotkey,%KeyName%
  33. gui,1:add,button,Default gbtnHK,Confirm
  34. gui,1:show,,%A_Space%
  35. return
  36. about:
  37. gui,2:Destroy
  38. gui,2:add,link,,%intro%
  39. gui,2:show,,About ScreenReader 0.1.1a
  40. return
  41. btnHK:
  42. gui,1:submit
  43. if (ChosenHotkey!=KeyName){
  44. Hotkey,%KeyName%,,off
  45. KeyName:=ChosenHotkey
  46. Hotkey,%KeyName%,main,on
  47. }
  48. gui,1:Destroy
  49. return
  50. main:
  51. MouseGetPos,x,y
  52. ;DllCall(vt)
  53. item:=GetElementItem(x,y)
  54. if !item.1
  55. return
  56. gui,3:Destroy
  57. ;gui,3:new,ToolWindow
  58. for k,v in item
  59. {
  60. gui,3:add,edit,x5 w480 -Tabstop vedit%k%,%v%
  61. gui,3:add,button,X+5 yp-2 vbtn%k% gcp2cb,To Clipboard
  62. }
  63. gui,3:show,,You Get
  64. return
  65. vas(obj,ByRef txt){
  66. for k,v in obj
  67. if (v=txt)
  68. return 0
  69. return 1
  70. }
  71. cp2cb:
  72. n:=SubStr(A_GuiControl,4)
  73. GuiControlGet,txt,,edit%n%
  74. if txt
  75. Clipboard:=txt
  76. gui,3:Destroy
  77. return
  78. 3GuiEscape:
  79. gui,3:Destroy
  80. return
  81. GetPatternName(id){
  82. global uia
  83. DllCall(vt(uia,50),"ptr",uia,"uint",id,"ptr*",name)
  84. return StrGet(name)
  85. }
  86. GetPropertyName(id){
  87. global uia
  88. DllCall(vt(uia,49),"ptr",uia,"uint",id,"ptr*",name)
  89. return StrGet(name)
  90. }
  91. GetElementItem(x,y){
  92. global uia
  93. item:={}
  94. DllCall(vt(uia,7),"ptr",uia,"int64",x|y<<32,"ptr*",element) ;IUIAutomation::ElementFromPoint
  95. if !element
  96. return
  97. DllCall(vt(element,23),"ptr",element,"ptr*",name) ;IUIAutomationElement::CurrentName
  98. DllCall(vt(element,10),"ptr",element,"uint",30045,"ptr",variant(val)) ;IUIAutomationElement::GetCurrentPropertyValue::value
  99. DllCall(vt(element,10),"ptr",element,"uint",30092,"ptr",variant(lname)) ;IUIAutomationElement::GetCurrentPropertyValue::lname
  100. DllCall(vt(element,10),"ptr",element,"uint",30093,"ptr",variant(lval)) ;IUIAutomationElement::GetCurrentPropertyValue::lvalue
  101. a:=StrGet(name,"utf-16"),b:=StrGet(NumGet(val,8,"ptr"),"utf-16"),c:=StrGet(NumGet(lname,8,"ptr"),"utf-16"),d:=StrGet(NumGet(lval,8,"ptr"),"utf-16")
  102. a?item.Insert(a):0
  103. b&&vas(item,b)?item.Insert(b):0
  104. c&&vas(item,c)?item.Insert(c):0
  105. d&&vas(item,d)?item.Insert(d):0
  106. DllCall(vt(element,21),"ptr",element,"uint*",type) ;IUIAutomationElement::CurrentControlType
  107. if (type=50004)
  108. e:=GetElementWhole(element),e&&vas(item,e)?item.Insert(e):0
  109. ObjRelease(element)
  110. return item
  111. }
  112. GetElementWhole(element){
  113. global uia
  114. static init:=1,trueCondition,walker
  115. if init
  116. init:=DllCall(vt(uia,21),"ptr",uia,"ptr*",trueCondition) ;IUIAutomation::CreateTrueCondition
  117. ,init+=DllCall(vt(uia,14),"ptr",uia,"ptr*",walker) ;IUIAutomation::ControlViewWalker
  118. DllCall(vt(uia,5),"ptr",uia,"ptr*",root) ;IUIAutomation::GetRootElement
  119. DllCall(vt(uia,3),"ptr",uia,"ptr",element,"ptr",root,"int*",same) ;IUIAutomation::CompareElements
  120. ObjRelease(root)
  121. if same {
  122. return
  123. }
  124. hr:=DllCall(vt(walker,3),"ptr",walker,"ptr",element,"ptr*",parent) ;IUIAutomationTreeWalker::GetParentElement
  125. if parent {
  126. e:=""
  127. DllCall(vt(parent,6),"ptr",parent,"uint",2,"ptr",trueCondition,"ptr*",array) ;IUIAutomationElement::FindAll
  128. DllCall(vt(array,3),"ptr",array,"int*",length) ;IUIAutomationElementArray::Length
  129. loop % length {
  130. DllCall(vt(array,4),"ptr",array,"int",A_Index-1,"ptr*",newElement) ;IUIAutomationElementArray::GetElement
  131. DllCall(vt(newElement,23),"ptr",newElement,"ptr*",name) ;IUIAutomationElement::CurrentName
  132. e.=StrGet(name,"utf-16")
  133. ObjRelease(newElement)
  134. }
  135. ObjRelease(array)
  136. ObjRelease(parent)
  137. return e
  138. }
  139. }
  140. variant(ByRef var,type=0,val=0){
  141. return (VarSetCapacity(var,8+2*A_PtrSize)+NumPut(type,var,0,"short")+NumPut(val,var,8,"ptr"))*0+&var
  142. }
  143. vt(p,n){
  144. return NumGet(NumGet(p+0,"ptr")+n*A_PtrSize,"ptr")
  145. }
Add Comment
Please, Sign In to add comment