some time ago i've written a mp3player-interface which was able to receive commands from the keyboard's playcontrol buttons - i had a logitech iTouch-keyboard where i had an ini-file to configure that thingy.
now i've got my laptop with those buttons. there is no special software intstalled. i can launch and control windows media player with them. now, is it possible to make my program receive that input? or is it something windows-internal i can't access?
tia
Posted on 2003-11-03 15:02:18 by hartyl
There are special scan codes for those buttons, perhaps look into keyboard hook.
Posted on 2003-11-03 16:10:58 by comrade
Posted on 2003-11-03 22:19:39 by Mecurius
thank you very much for your answer!
i just had no time for implementing that stuff, but i've done it now.
however, i've discovered a problem already; i use the following code:


WM_APPCOMMAND equ 319h
APPCOMMAND_MEDIA_NEXTTRACK equ 11
APPCOMMAND_MEDIA_PREVIOUSTRACK equ 12
APPCOMMAND_MEDIA_STOP equ 13
APPCOMMAND_MEDIA_PLAY_PAUSE equ 14

.elseif eax==WM_APPCOMMAND
mov eax,lParam
shr eax,16
and ax,7fffh

.if ax==APPCOMMAND_MEDIA_NEXTTRACK
mov eax,IDC_NEXT
invoke SendMessage,hWin,WM_COMMAND,eax,0
.elseif ax==APPCOMMAND_MEDIA_PREVIOUSTRACK
mov eax,IDC_PREV
invoke SendMessage,hWin,WM_COMMAND,eax,0
.elseif ax==APPCOMMAND_MEDIA_STOP
mov eax,IDC_STOP
invoke SendMessage,hWin,WM_COMMAND,eax,0
.elseif ax==APPCOMMAND_MEDIA_PLAY_PAUSE
mov eax,IDC_PLAYPAUSE
invoke SendMessage,hWin,WM_COMMAND,eax,0
.else
xor eax,eax
ret
.endif


this works perfectly, as it should; but only when the window has the focus! i've checked windows media player. that one works without focus as well. I have to add, that i use a windows without a window-frame and without a taskbar-button-thingy. furthermore i've tested it with a normal window, which also didn't work without focus.
so, do you have any idea how i could get the message without focus as well?
Posted on 2003-11-16 15:22:52 by hartyl
The only thing I can think of is to use a Windows Hook (SetWindowsHookEx) with WH_GETMESSAGE. You cannot use the keyboard hook since the special keys use that appcommand message instead of the normal keyboard messages.
Posted on 2003-11-16 16:52:23 by Mecurius
thanks for your quick reply; unfortunately this doesn't seem to work. please take a look at my code (currently in c since the assembler doesn't work on that xp-machine). actually i think that it works your way, but not with my code i've created:



;the hook-proc
HHOOK hMessage=0;

LRESULT CALLBACK GetMsgProc(int code,WPARAM wParam,LPARAM lParam)
{ MSG *message=(MSG*)lParam;
CallNextHookEx(hMessage,code,wParam,lParam);

if(message->message==WM_APPCOMMAND)
{ MessageBox(NULL,"hook","test",MB_OK);
}
return 0;
}

;the window-proc
switch( message )
{ case WM_CREATE:
MessageBox(hWnd,"hook installed","out",MB_OK);
hMessage=SetWindowsHookEx(WH_GETMESSAGE,&GetMsgProc,hInst,NULL);
break;
:
}


the SetWindowsHookEx-function returns non-zero and i get the messagebox. but i don't get any message via the hook when i press a button. i.e. the hook doesn't work at all. and idea why?
Posted on 2003-11-17 13:38:24 by hartyl
Hi :)
If you're getting the messagebox then the hook is working. Perhaps there's a problem when sending messages back to the main program, remember you should use a shared section in your hook DLL to get the hook handle and any other data you might want to pass to your hook handler.
Posted on 2003-11-17 13:53:03 by QvasiModo
nah! expressed me wrong i think; i meant the messagebox saying "hook installed", but not the one with "hook".. obviously it's not working then
Posted on 2003-11-18 03:05:29 by hartyl