Results 1 to 9 of 9

Thread: Capture Game Screen (Game Uses DirectX)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Capture Game Screen (Game Uses DirectX)

    I need to capture the screen when a game is running.
    The problem is that when I make my app use keybd_event API to simulate the PrintScreen button, or when I use BitBlt to capture the screen, the window that the game is in is just black.

    I need to capture the screen because I want to look for certain pixels within the game window, but atm the whole thing is just black.

    Any way to capture the pixels in the window or somehow compare the pixels to a picture I have (sort of like an OCR but I want to find shapes, not text)
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  2. #2
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Capture Game Screen (Game Uses DirectX)

    if u manually press print screen does it work??
    is there a screenshot hotkey for the game? maybe send that key?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Capture Game Screen (Game Uses DirectX)

    The strange thing is that if I manually press print screen then it works fine, but if I make the prog do it it just captures blackness
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Capture Game Screen (Game Uses DirectX)

    I'm using the keybd_event API to send the printscrn key.
    Is the game somehow detecting this and preventing my app from capturing the screen or what?

    Is it possible to programmatically capture the screen within a game?
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  5. #5
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: Capture Game Screen (Game Uses DirectX)

    If pressing the print screen key is the only way to grab the image. Then, use it. In your program add a timer. In the timer check the clipboard for an image. If there's an image then transfer it to a picturebox,clear the clipboard and then analyze it.

    Something like:
    VB Code:
    1. Private Sub Timer1_Timer()
    2.     If Clipboard.GetFormat(vbCFBitmap) Then
    3.         Picture1.Picture = Clipboard.GetData(vbCFBitmap)
    4.         Clipboard.Clear
    5.         'analyze picture
    6.     End If
    7. End Sub
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

  6. #6
    New Member
    Join Date
    Jan 2006
    Posts
    3

    Re: Capture Game Screen (Game Uses DirectX)

    Hi

    Please excuse me for sticking my nose in here but how might you then store/write that graphic file to a predetermined folder with say an automated date and time stamp as the file name...!

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Capture Game Screen (Game Uses DirectX)

    The problem is that I want to analyze the screen in real-time (or as close to it as I can get) so that I can basically have my program understand what is happening in the game without me having to press PrintScrn every second.

    I want it to capture the screen continuously and then it will work like an OCR and look for certain things within the game screen.

    @berzerkart, you would use SavePicture Picture1.Picture, App.Path & "\" & Now & ".bmp"
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  8. #8
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: Capture Game Screen (Game Uses DirectX)

    hmmm. That's a tough one.

    Is the game somehow detecting this and preventing my app from capturing the screen or what?
    I doubt it. Because the first thing it would do is block the print screen button. It's more likely that it's blocking keys to prevent cheating.

    You tried to BitBlt. Maybe it's using DirectX. Does that use the same draw method. Would you have to grab it differently from DirectX ?

    This is what I use.

    VB Code:
    1. '
    2. Declare Sub keybd_event Lib "user32" _
    3. (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, _
    4. ByVal dwExtraInfo As Long)
    5. Const VK_SNAPSHOT = &H2C
    6.  
    7. 'The following command copies the full windows desktop to the clipboard (the equivalent of PrintScrn):
    8.  
    9.    call keybd_event(vbKeySnapshot, 0, 0, 0)
    10.  
    11. 'The following command copies the active application window to the clipboard (the equivalent of Alt+PrintScrn):
    12.  
    13.    call keybd_event(vbKeySnapshot, 1, 0, 0)
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Capture Game Screen (Game Uses DirectX)

    That's basically what I was using
    VB Code:
    1. Public Function SaveScreen(pstrFileName As String) As Boolean
    2.  
    3. 'To get the Entire Screen
    4. Call keybd_event(vbKeySnapshot, 1, 0, 0)
    5.  
    6. 'To get just the Active Window
    7. 'Call keybd_event(vbKeySnapshot, 0, 0, 0)
    8.  
    9. On Error GoTo SaveErr
    10.  
    11. SavePicture Clipboard.GetData(vbCFBitmap), pstrFileName
    12.  
    13. SaveScreen = True
    14. SaveErr:
    15. End Function
    Is there some other way to 'see' what's on the screen?
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

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