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
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
There are special scan codes for those buttons, perhaps look into keyboard hook.
Is this what you're looking for?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/wm_appcmd.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputmessages/wm_appcommand.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/wm_appcmd.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputmessages/wm_appcommand.asp
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:
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?
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?
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.
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 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?
;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?
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.
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.
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