Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. accessing the key buffer

accessing the key buffer

Scheduled Pinned Locked Moved C#
helptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Ylis
    wrote on last edited by
    #1

    I'm trying to make an app that catches the clipboard data when somebody press print screen. The problem I'm facing is to determin if the user has pressed print screen, the event needs to be triggerd even if my app doesn't have focus. So what I'm wondering is if there's any reliable way to do this without hooks and that sort of stuff (which I know nothing about hehe). All I need is some keywords or perhaps a good article/tutorial :). just figured it out, no need to answer this one.

    H 1 Reply Last reply
    0
    • Y Ylis

      I'm trying to make an app that catches the clipboard data when somebody press print screen. The problem I'm facing is to determin if the user has pressed print screen, the event needs to be triggerd even if my app doesn't have focus. So what I'm wondering is if there's any reliable way to do this without hooks and that sort of stuff (which I know nothing about hehe). All I need is some keywords or perhaps a good article/tutorial :). just figured it out, no need to answer this one.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Since your application doesn't worn the desktop window, you'd have to set a Windows hook. They're not as hard as you think, and MSDN even has examples. Lookup the functions SetWindowsHookEx and UnhookWindowsHook. The topic "Win32 Hooks" even has sample code. Another way might be to P/Invoke the functions SetClipboardViewer and ChangeClipboardChain. Then call SetClipboardViewer with your window handle (Form.Handle.ToInt32()). When the clipboard is changed, your application is sent the WM_DRAWCLIPBOARD message (DWORD, 0x0308). You must also P/Invoke SendMessage so that when WM_CHANGECBCHAIN is passed (when the clipboard chain changes, i.e. a viewer is added or removed) you can pass the HANDLEs that you received from calling SetClipboardViewer. This may sound complicated, but it's not. Essentially, you're just inserting yourself in a chain and handling messages passed to that chain. When you get the WM_DRAWCLIPBOARD message, you can use all the .NET class library's members for accessing the clipboard, checking for DataFormats.Bitmap or some other string (even your own). This would tell you that an image was copied, though, not that the PrintScreen key was pressed. You could compare the size of the image with the size of the screen, but that only gives you a probable screenshot. Basically, a windows hook is the way to go if you want a true handle for PrintScreen. The other is just an alternative if you just want to know when an image was copied to the clipboard.

      Reminiscent of my younger years...

      10 LOAD "SCISSORS" 20 RUN

      Y 1 Reply Last reply
      0
      • H Heath Stewart

        Since your application doesn't worn the desktop window, you'd have to set a Windows hook. They're not as hard as you think, and MSDN even has examples. Lookup the functions SetWindowsHookEx and UnhookWindowsHook. The topic "Win32 Hooks" even has sample code. Another way might be to P/Invoke the functions SetClipboardViewer and ChangeClipboardChain. Then call SetClipboardViewer with your window handle (Form.Handle.ToInt32()). When the clipboard is changed, your application is sent the WM_DRAWCLIPBOARD message (DWORD, 0x0308). You must also P/Invoke SendMessage so that when WM_CHANGECBCHAIN is passed (when the clipboard chain changes, i.e. a viewer is added or removed) you can pass the HANDLEs that you received from calling SetClipboardViewer. This may sound complicated, but it's not. Essentially, you're just inserting yourself in a chain and handling messages passed to that chain. When you get the WM_DRAWCLIPBOARD message, you can use all the .NET class library's members for accessing the clipboard, checking for DataFormats.Bitmap or some other string (even your own). This would tell you that an image was copied, though, not that the PrintScreen key was pressed. You could compare the size of the image with the size of the screen, but that only gives you a probable screenshot. Basically, a windows hook is the way to go if you want a true handle for PrintScreen. The other is just an alternative if you just want to know when an image was copied to the clipboard.

        Reminiscent of my younger years...

        10 LOAD "SCISSORS" 20 RUN

        Y Offline
        Y Offline
        Ylis
        wrote on last edited by
        #3

        thx, I'm looking into it :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups