Results 1 to 7 of 7

Thread: [RESOLVED] [2005] Intercept PrintScreen

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    115

    Resolved [RESOLVED] [2005] Intercept PrintScreen

    I am trying to make my app take a screenshot, and save it to a file! Ive read several places on how to do this in VB.Net, but for some reason, I havent been able to do what I want, which is the following.

    You start the program, and hit "go".. the program then minimizes.. When the user hits the PrintScreen key, the program should intercept it, and save the screenshot to a file and preview it in an picturebox.

    Maybe this is impossible and I have to do it another way, just thought I would check it!

    Cheers!

  2. #2
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2005] Intercept PrintScreen

    Gig wrote a nice Class capable of this function, see http://www.vbforums.com/showthread.php?t=385497

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    115

    Re: [2005] Intercept PrintScreen

    Cool! Thanks..

    I still wonder though.. How can I get my application to take the screenshot whenever the user hits the printscreen button?

    Example: The program is minimized, and the user hits printScreen.. the capturescreenshot event is fired.. Not sure how to do this
    Last edited by Untouchab1e; May 15th, 2007 at 08:01 PM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Intercept PrintScreen

    You can detect external key presses with a keyboard hook. The topic has been discussed often so a search should turn up plenty of information. I'm not sure if you can then "cancel" the key press to prevent the OS acting on it further. That's what research is for though, eh?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: [2005] Intercept PrintScreen

    If you register PrtSc as a hotkey (using the RegisterHotkey API) it won't be passed on to the operating system after you app has handled it.

    For a WH_KEYBOARD_LL hook, return 1 to prevent the OS processing it (as per msdn)

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    115

    Re: [2005] Intercept PrintScreen

    Thanks for replies.. but where can I find the RegisterHotkey API? Tried searching abit, but obviously not good enough!

    Thanks!

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Posts
    115

    Re: [2005] Intercept PrintScreen

    Resolved using the following Code:

    Code:
    Public Class Form1
     
    Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
    Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
    Public Const WM_HOTKEY As Integer = &H312
     
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = WM_HOTKEY Then
            ' Pressed the hotkey!
            Debug.WriteLine(m.Msg.ToString & ":" & m.WParam.ToString & ":" & m.LParam.ToString)
        End If
        MyBase.WndProc(m) '<-- Never Ever Forget This!
    End Sub
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Call UnregisterHotKey(Me.Handle, 9) '<-- Don't forget this
    End Sub
     
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call RegisterHotKey(Me.Handle, 9, 0, 44) '<-- Play with these settings
    End Sub
    End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width