title: Invoke a Sub when I press a key in vba powerpoint
body: <p>This code captures the active window and paste it to power point slides by taking number screenshots to be pasted, by calling a <code>sub PrintScreen</code>, After that it takes 5 seconds to capture screen of active window. While i want that whenever i press a specific key like 'F7 or F3 etc' it should take print screen instead of waiting 5 seconds. I just want to press the key and it invokes sub in which i specify the print and paste and other functions.</p>
  
  <pre><code>Sub Screen_Capture_VBA()
   Dim Sec4 As Date
   MsgBox "Note: Three seconds after you click OK " &amp; _
   "the active window will be copied to the clipboard."
   Sec4 = DateAdd("s", 4, Now)
   myValue = InputBox("Give me no of screen shots you want to capture")
   For I = 1 To myValue
   PrintScreen
   Next I
  End Sub
  </code></pre>
  
  <p>This is my print screen sub.</p>
  
  <pre><code>Sub PrintScreen()
  
  Sleep 5000
  keybd_event VK_MENU, 0, 0, 0
  keybd_event VK_SNAPSHOT, 0, 0, 0
  keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
  keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
  
  ActivePresentation.Slides.Add 1, ppLayoutBlank
  ActivePresentation.Slides(1).Shapes.Paste
  
  End Sub
  </code></pre>