powerpoint.ahk 4.2 KB

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