Click here to Skip to main content
15,888,208 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I want to execte my code after a snap is taken. How can I trap the camera keypress event?

Please help me.
Posted
Updated 22-Feb-10 4:22am
v2

Disclaimer:
1) I know this works for WinMo6 (it does on my phone). I'm not sure if it will work on WinMo5.
2) My answer is based on c/c++. Your question is tagged c#. But i'm assuming that you only need an idea on how and not the actual code.

Ok, here goes.
You first need to install a keyboard hook.
The way to do this is to use the "SetWindowsHookExW" procedure available in coredll.dll.

Below i've pasted some code snippet from my code. It should be easy to figure out.

<pre>// Define the function types used by hooks
typedef LRESULT (CALLBACK *PFNHOOKPROC)(int code, WPARAM wParam, LPARAM lParam);
typedef HHOOK (WINAPI *PFNSETWINDOWSHOOKEXW)(int idHook, PFNHOOKPROC lpfn, HINSTANCE hMod, DWORD dwThreadId);
typedef LRESULT (WINAPI *PFNCALLNEXTHOOKEX)(HHOOK hhk, int nCode, WPARAM wParam, LPARAM lParam);
typedef LRESULT (WINAPI *PFNUNHOOKWINDOWSHOOKEX)(HHOOK hhk);

// For the low level keyboard hook, the keyboard procedures is passed a pointer to KBDLLHOOKSTRUCT instance
typedef struct
{
DWORD vkCode;
DWORD scanCode;
DWORD flags;
DWORD time;
ULONG_PTR dwExtraInfo;
} KBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;


// Win32 Hook APIs
static PFNSETWINDOWSHOOKEXW fpSetWindowsHookEx = NULL;
static PFNUNHOOKWINDOWSHOOKEX fpUnhookWindowsHookEx = NULL;
static PFNCALLNEXTHOOKEX fpCallNextHookEx = NULL;</pre>


<pre>//BOOL InstallKBDHook(HINSTANCE hInstance)
{
hmCoreDll = LoadLibrary(_T("coredll.dll"));
if(hmCoreDll == NULL)
{
return false;
}
else
{
fpSetWindowsHookEx = (PFNSETWINDOWSHOOKEXW)GetProcAddress(hmCoreDll, _T("SetWindowsHookExW"));
if(fpSetWindowsHookEx == NULL)
{
UnLoadCoreDll();
return false;
}
else
{
hhkInstalledHook = fpSetWindowsHookEx(WH_KEYBOARD_LL, KBDHookCallBackFunction, hInstance, 0);
if(hhkInstalledHook == NULL)
{
UnLoadCoreDll();
return false;
}
}

fpCallNextHookEx = (PFNCALLNEXTHOOKEX)GetProcAddress(hmCoreDll, _T("CallNextHookEx"));
if(fpCallNextHookEx == NULL)
{
UnLoadCoreDll();
return false;
}

fpUnhookWindowsHookEx = (PFNUNHOOKWINDOWSHOOKEX)GetProcAddress(hmCoreDll, _T("UnhookWindowsHookEx"));
if(fpUnhookWindowsHookEx == NULL)
{
UnLoadCoreDll();
return false;
}
}
return true;
}</pre>


The "KBDHookCallBackFunction" above is the function you would write to capture the key events.

<pre>__declspec(dllexport) LRESULT CALLBACK KBDHookCallBackFunction( int nCode, WPARAM wParam, LPARAM lParam )
{
static volatile PKBDLLHOOKSTRUCT pkbhData = (PKBDLLHOOKSTRUCT)lParam;
return fpCallNextHookEx(hhkInstalledHook, nCode, wParam, lParam);
}</pre>

One of the parameters in pkbhData will be you keycode. You will need to find the actual key code for the camera button.

Good Luck!
 
Share this answer
 
Plz Send me in C#.net Code if ur able to send me



i dont no about KBHook plz tell me that also


Regards

Chetan
 
Share this answer
 
Sorry, i can't do that. my c# isn't that good.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900