Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect keypress F12 in a game

Status
Not open for further replies.

BobbaFet

Programmer
Feb 25, 2001
903
NL
Hi all,
I've made a screenshot taker using the key press detection code mentioned in this thread: thread102-659412

Now this works fine in every application that I tried, makes a nice screenshot and saves it to the harddrive in JPEG format, but when I load Ghost Recon (the game this is intended for, as a part of the manager that Im making) it won't detect the keypress, can anyone explain to me why that could be? And how I could make it so it does detect the keypress?

(For those of you who play Ghost Recon, yes I am aware that Ghost Recon has a screenshot taking functionality built in, but that saves in BMP format which doesnt load properly into Delphi, and also results in gigantic files in the order of 2 - 3 MB, also there being a maximum to the number of screenshots that you can take, which results in files being overwritten)

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Some of my thoughts:

- Are you sure that F12 isn't still assigned to a function within Ghost Recon? If it is, it's probably being 'handled' and then the keypress is discarded so your program doesn't see it.

- Remembering from my days writing TSRs in Pascal, hooking into to the keyboard meant watching for keypresses, handling them as necessary, and then passing them back to the previous hook program for them to handle. Perhaps Ghost Recon isn't doing this? One way to defeat this may be to have your program load after Ghost Recon has. This could mean your program gets first dibs on any keystrokes.

One way to do this would be to set up a batch file ie. GhostR.bat
Code:
start c:\games\ghost.exe
sleep 60
start c:\myprogs\sshot.exe

change as necessary - you may need to write the sleep program so that the batch script pauses for long enough for Ghost Recon to have set up it's key hooks. Adding 'start' before the lines means that the batch program proceeds after loading the program. Without it, it would pause until the program terminates.

This is all theory btw - let us know if you try it and it works.
 
I have checked it just to be sure but F12 isnt used. And in fact would be illogical to use as all the controls are on the left side of the keyboard.

To be even more sure I assigned some "odd" keypress combinations like shift+backspace and alt+prntscrn. But they didn't give any results either.

The loading Ghost Recon before my prog unfortunately didnt work either.

I just thought of something, maybe I should instead of hooking it into Windows hook it into Ghost Recon itself, any thoughts on how to go about such a thing?

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Well - at this point, I would be focussing on a workaround. Writing a handler for the BMPs to convert to JPGs and rename would be an idea - but you say the BMPs don't load correctly in Delphi? There are a couple of versions of BMP. RLE and RGB are two that spring two mind, perhaps searching for a BMP component might give you something that Delphi can use to convert the images.
 
The thing is with them not loading properly is that I only get the bottom 1/3 correctly and the rest will be black.

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Hi BobbaFet,

you can try to implement a global keyboard hook? (if ghost recon uses windows keyboard handling offcourse).

for more info & links look here :
thread102-853200

cheers

--------------------------------------
What You See Is What You Get
 
Im very sorry but I dont understand the code posted there, and how do I get information from the DLL to my application? And how do I activate it? And why do I keep getting this in this part of the code:
Code:
Exports
  KeyBoardProc name 'KEYBOARDPROC',
  GetHookRecPointer name 'GETHOOKRECPOINTER',
  StartKeyBoardHook name 'STARTKEYBOARDHOOK',
  StopKeyBoardHook name 'STOPKEYBOARDHOOK';

"Undeclared Identifier: StartKeyBoardHook"
"Undeclared Identifier: StopKeyBoardHook"?

Do I need to comment these out and call them from within the DLL?

When I click "New" > "Other" > "DLL Wizard" there is a large comment area which says:

Code:
{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

So this then means that I have got to use ShareMem in both the dll and my application and that I'll need to return them as PChar() so that I dont need to send BORLNDMM.DLL with my program. Does this apply to this hook dll as well?

Also there is some memory management code present here in this code, is this the cause that I don't see ShareMem in the uses list? Or is it for something else, because if it
is, I won't need it, all I need is to detect which key has
been pressed and that's all I need to be passed back to my
application.

I'm using Borland Delphi 7 Enterprise.

Sorry for all these questions but I've never programmed with DLLs before, and this is also the first time that I am outside my usual meddling with the file system and strings and such, I just program out of hobby, so please be patient with me.

Thanx,

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
I would also just like to state that reading the helpfile has left me confused and disorientated.

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Hi Bobbafet,

I'll be patient with you :))
if you have read the thread completely you would have seen that you'll need to use the windows API function 'setwindowshookex' to actually install the keyboard hook (links are provided in the thread. concerning sharemem & dll's, you'll only need this if you're passing string types towards dll functions/procedures. so Pchar's are ok, but beware with those, as you need to allocate them on the calling side...

anyway, this is not easy stuff and I understand this may bring some confusion...

--------------------------------------
What You See Is What You Get
 
Bobba
I would guess that most 'Big' games these days dont use Windows at all but are based on their own OS and handeling the graphics/sound cards directly, Windows must still be running in the background or your program wouldnt work at all.
But if I understand you correctly you do get partial screens, this would be consistant with the game interupting your proccess at a machine level.
As for hacking the game, I am sure it's possible, but we arn't talking Delphi Pascal here!!


Steve
Those who know me have no need of my name. SD
 
When you use the screenshot taker that is built into Ghost Recon it'll leave a file like for example ScreenShot1.bmp, if I load this file into a Delphi's TBitMap it shows the bottom 1/3 and leaves the rest black, but this has nothing to do with my program taking screenshots. I think that it is just Delphi's TBitMap that is incompatible.

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top