Hello there!
I need a little help with a key detection program, i only need to watch for 1 key just -like the method to start recording with fraps-.
I'm trying to use WH_KEYBOARD hook(not the WH_KEYBOARD_LL because i need the program to do stuff while "hooking").
In the dll i need to determine which key was pressed, but i have no idea ,how could i do that,so please give me an example.
Also ,if you would be so kind to check my code if i made any mistakes.
So here is "my"-mostly copied from other sites-code:
The Main program
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
HOOKPROC hkprcSysMsg;
HINSTANCE hinstDLL;
HHOOK hhookSysMsg;
hinstDLL = LoadLibrary(TEXT("C:\\cppprojdll.dll"));
hkprcSysMsg = (HOOKPROC)GetProcAddress(hinstDLL, "KeyboardProc");
hhookSysMsg = SetWindowsHookEx(WH_KEYBOARD,hkprcSysMsg,hinstDLL,0);
//here the program should execute the code from the dll , but i don't have any idea ,how to do that :(
UnhookWindowsHookEx(hhookSysMsg);
}
The Dll
DLL_Tutorial.h
#ifndef _DLL_TUTORIAL_H_
#define _DLL_TUTORIAL_H_
#include <iostream>
#include <windows.h>
#if defined DLL_EXPORT
#define DECLDIR __declspec(dllexport)
#else
#define DECLDIR __declspec(dllimport)
#endif
extern "C"
{
DECLDIR LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
}
#endif
DLLTutorial.cpp
#include <iostream>
#include "DLL_Tutorial.h"
#include <windows.h>
#define DLL_EXPORT
extern "C"
{
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{ if (nCode < 0)
return CallNextHookEx(NULL, nCode, wParam, lParam);
///here the program should print "key e is pressed" ,when it's pressed
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
}
Well guys, i'm sorry for wasting your time, with all theese noob problems =/
But if you have a little time to explain this thing to me, please do so.
Thanks & Have a nice day!
Andrew