+ Reply to Thread
Results 1 to 2 of 2

Thread: Integrate Media Keys into applicaiton

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    17

    Integrate Media Keys into applicaiton

    Lets say you got a laptop or a multimedia keybaord enabled.
    And you want to create a simple media player that play/pause, stop, next/previous songs depends on the multimedia key you press.

    How can i do that ?
    Last edited by jemmy; 11-02-2012 at 01:34 PM.

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    10
    Steps :
    -------
    1- create a windows form application
    2- On form choose events and choose : Form1_KeyPress


    Namespaced to be used :
    -----------------------
    Code:
    using System.Runtime.InteropServices;
    using System.Diagnostics;
    Coding :
    --------
    Code:
            protected override void WndProc(ref Message msg)
            {
                if (msg.Msg == 0x319)   // WM_APPCOMMAND message
                {
                    // extract cmd from LPARAM (as GET_APPCOMMAND_LPARAM macro does)
                    int cmd = (int)((uint)msg.LParam >> 16 & ~0xf000);
                    switch (cmd)
                    {
                        case 13:  // APPCOMMAND_MEDIA_STOP constant
                            // add your function here in case of Stop button is pressed
                            break;
                        case 14:  // APPCOMMAND_MEDIA_PLAY_PAUSE
                            // add your function here in case of Play/Pause button is pressed
                            break;
                        case 11:  // APPCOMMAND_MEDIA_NEXTTRACK
                            // add your function here in case of Next button is pressed
                            break;
                        case 12:  // APPCOMMAND_MEDIA_PREVIOUSTRACK
                            // add your function here in case of Previous button is pressed
                            break;
                        default:
                            break;
                    }
                }
                base.WndProc(ref msg);
            }
    
    
            private void Form1_KeyPress(object sender, KeyPressEventArgs e)
            {
                Message m = new Message();
                m.Msg = e.KeyChar;
    
                WndProc(ref m);
            }
    And once you click on each multimedia key a specific function will be done based on your coding.
    And in case your media keys on your applications are buttons [i.e : the user click a button to pause/play a song] then
    inside the function you can add :
    Code:
    Button1_Click(new object(),new EventArgs());
    That will click the button programatically in case any media key is pressed

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts