powerpoint2013.ahk 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #include, Gdip.ahk
  2. FileReadLine, __Width, Resolution_Configuration.txt, 2
  3. FileReadLine, __Height, Resolution_Configuration.txt, 3
  4. FileReadLine, __SlideWidth, Resolution_Configuration.txt, 5
  5. FileReadLine, __SlideHeight, Resolution_Configuration.txt, 6
  6. F5::
  7. try{
  8. ppt := ComObjActive("PowerPoint.Application")
  9. objppt := ppt.ActivePresentation
  10. TotalSlides:=% objppt.Slides.Count
  11. FileCreateDir, temp
  12. }
  13. catch e {
  14. return
  15. }
  16. SysGet, MonitorCount, MonitorCount
  17. ppt := objppt.SlideShowSettings
  18. ppt.Run
  19. Return
  20. Space::
  21. try{
  22. ppt := ComObjActive("PowerPoint.Application")
  23. objppt := ppt.ActivePresentation
  24. SlideNum :=% objppt.SlideShowWindow.View.Slide.SlideIndex
  25. }
  26. catch e {
  27. ExitApp
  28. }
  29. saveScreenshot(SlideNum)
  30. objppt.SlideShowWindow.View.Next
  31. monitorDisplay(objppt, MonitorCount)
  32. return
  33. v::
  34. try{
  35. ppt := ComObjActive("PowerPoint.Application")
  36. objppt := ppt.ActivePresentation
  37. objppt.SlideShowWindow.View.Previous
  38. }
  39. catch e {
  40. ExitApp
  41. }
  42. monitorDisplay(objppt, MonitorCount)
  43. return
  44. ;Select the slides and calls setDisplay
  45. monitorDisplay(objppt, MonitorCount){
  46. try{
  47. CurrentSlideNumber :=% objppt.SlideShowWindow.View.Slide.SlideIndex
  48. }
  49. catch{
  50. FileRemoveDir, temp, 1
  51. ExitApp
  52. }
  53. monitor := MonitorCount-1
  54. var2 := 0
  55. ;MsgBox %monitor%
  56. Loop %monitor%{
  57. var2++
  58. setDisplay(var2, CurrentSlideNumber-1)
  59. if(var2 > 1){
  60. CurrentSlideNumber--
  61. }
  62. }
  63. }
  64. ;Coordinates for setting the display are returned
  65. getCoordinates(MonitorNumber){
  66. SysGet, MonitorCount, MonitorCount
  67. SysGet, MonitorPrimary, MonitorPrimary
  68. Array := Object()
  69. Loop, %MonitorCount%
  70. {
  71. ArrayCount += 1
  72. SysGet, MonitorName, MonitorName, %A_Index%
  73. SysGet, Monitor, Monitor, %A_Index%
  74. SysGet, MonitorWorkArea, MonitorWorkArea, %A_Index%
  75. Array.Insert(MonitorLeft)
  76. }
  77. SortArray(Array)
  78. if(MonitorNumber = 2)
  79. return Array[3]
  80. if(MonitorNumber = 3)
  81. return Array[4]
  82. }
  83. ;Using the coordinates returned from getCoordintes
  84. ;The screenshots are set to the external displays
  85. setDisplay(MonitorNumber, PreviousSlideNumber){
  86. global
  87. coord := getCoordinates(MonitorNumber)
  88. SetEnv file, %A_WorkingDir%\temp\%PreviousSlideNumber%.png
  89. if(MonitorNumber = "1"){
  90. return
  91. }
  92. Gui, %MonitorNumber%:destroy
  93. Gui, %MonitorNumber%:+AlwaysOnTop +LastFound +Owner -Caption
  94. Gui, %MonitorNumber%:Color, Black
  95. Gui, %MonitorNumber%:Add, Picture, w%__Width% h%__Height%, %file%
  96. Gui, %MonitorNumber%:Show, x%coord% y0 maximize
  97. }
  98. ;Uses gdip library to get the screenshots
  99. ;screen variable is of the format x coordinate| y coordinate| width| height
  100. Screenshot(outfile)
  101. {
  102. SysGet, MonitorCount, MonitorCount
  103. SysGet, MonitorPrimary, MonitorPrimary
  104. Array := Object()
  105. Loop, %MonitorCount%
  106. {
  107. ArrayCount += 1
  108. SysGet, MonitorName, MonitorName, %A_Index%
  109. SysGet, Monitor, Monitor, %A_Index%
  110. SysGet, MonitorWorkArea, MonitorWorkArea, %A_Index%
  111. Array.Insert(MonitorLeft)
  112. }
  113. SortArray(Array)
  114. res := Array[2]
  115. FileReadLine, __SlideWidth, Resolution_Configuration.txt, 5
  116. FileReadLine, __SlideHeight, Resolution_Configuration.txt, 6
  117. slideWidth := __SlideWidth
  118. slideHeight := __SlideHeight
  119. pToken := Gdip_Startup()
  120. screen=%res%|0|%slideWidth%|%slideHeight%
  121. pBitmap := Gdip_BitmapFromScreen(screen)
  122. Gdip_SaveBitmapToFile(pBitmap, outfile, 100)
  123. Gdip_DisposeImage(pBitmap)
  124. Gdip_Shutdown(pToken)
  125. }
  126. ;Screenshot is saved into a temp folder with slide number as the names
  127. saveScreenshot(SlideNumber){
  128. file := A_WorkingDir . "\temp\" . SlideNumber . ".png"
  129. Screenshot(file)
  130. }
  131. ;Coordinates of the display are sorted using this function
  132. SortArray(Array, Order="A") {
  133. ;Order A: Ascending, D: Descending, R: Reverse
  134. MaxIndex := ObjMaxIndex(Array)
  135. If (Order = "R") {
  136. count := 0
  137. Loop, % MaxIndex
  138. ObjInsert(Array, ObjRemove(Array, MaxIndex - count++))
  139. Return
  140. }
  141. Partitions := "|" ObjMinIndex(Array) "," MaxIndex
  142. Loop {
  143. comma := InStr(this_partition := SubStr(Partitions, InStr(Partitions, "|", False, 0)+1), ",")
  144. spos := pivot := SubStr(this_partition, 1, comma-1) , epos := SubStr(this_partition, comma+1)
  145. if (Order = "A") {
  146. Loop, % epos - spos {
  147. if (Array[pivot] > Array[A_Index+spos])
  148. ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos))
  149. }
  150. } else {
  151. Loop, % epos - spos {
  152. if (Array[pivot] < Array[A_Index+spos])
  153. ObjInsert(Array, pivot++, ObjRemove(Array, A_Index+spos))
  154. }
  155. }
  156. Partitions := SubStr(Partitions, 1, InStr(Partitions, "|", False, 0)-1)
  157. if (pivot - spos) > 1 ;if more than one elements
  158. Partitions .= "|" spos "," pivot-1 ;the left partition
  159. if (epos - pivot) > 1 ;if more than one elements
  160. Partitions .= "|" pivot+1 "," epos ;the right partition
  161. } Until !Partitions
  162. }
  163. ESC::
  164. objppt.SlideShowWindow.View.Exit
  165. FileRemoveDir, temp, 1
  166. ExitApp