Click here to Skip to main content
15,898,134 members
Home / Discussions / C#
   

C#

 
GeneralRe: Streams and Cryptography (Padding is invalid and cannot be removed) Pin
Paulo Zemek5-Jan-10 10:09
Paulo Zemek5-Jan-10 10:09 
AnswerRe: Streams and Cryptography (Padding is invalid and cannot be removed) Pin
Skippums5-Jan-10 10:30
Skippums5-Jan-10 10:30 
QuestionNeed help! How to draw waveform of the sound when playing video! Pin
die_for_rock_vn5-Jan-10 7:23
die_for_rock_vn5-Jan-10 7:23 
AnswerRe: Need help! How to draw waveform of the sound when playing video! Pin
Roger Wright5-Jan-10 20:02
professionalRoger Wright5-Jan-10 20:02 
Questionenumerate used com Pin
abalbo5-Jan-10 3:21
abalbo5-Jan-10 3:21 
AnswerRe: enumerate used com Pin
Keith Barrow5-Jan-10 7:15
professionalKeith Barrow5-Jan-10 7:15 
GeneralRe: enumerate used com Pin
abalbo5-Jan-10 16:11
abalbo5-Jan-10 16:11 
QuestionDetecting music keys from keyboard in winform app Pin
Wheels0125-Jan-10 2:22
Wheels0125-Jan-10 2:22 
Good morning.

I am trying to detect the music button events from the keyboard, but have been unsuccessful so far. I have the following code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.Collections;

namespace KPlayer
{
    public partial class Form1 : Form
    {
        WMPLib.WindowsMediaPlayer wmp = new WMPLib.WindowsMediaPlayer();
        WMPLib.IWMPPlaylist pl;
        //WMPLib.IWMPPlaylistArray plItems; 
        WMPLib.IWMPMedia media;

        // Required designer variable
        //private System.ComponentModel.Container components = null;

        ArrayList ar = new ArrayList();
        int intCount = 0;      
        List<int> numbers = new List<int>();
      
        float currentSize = 10;
        string currentFont = "DS-Digital";

        public Form1()
        {
            // Required for Windows Form Designer support
            InitializeComponent();
        }
       
        [STAThread]
        // Declare Windows API calls used to access Windows hooks
        [DllImport("user32.dll")]

        public static extern int SetWindowsHookEx(int hookType,
                                                   HookProc callback,
                                                   int instance,
                                                   int threadID);
        [DllImport("user32.dll")]
        public static extern int CallNextHookEx(int hookHandle, int code,
                                                int wparam, int lparam);
        [DllImport("user32.dll")]
        public static extern bool UnhookWindowsHookEx(int hookHandle);
        [DllImport("user32.dll")]
        public static extern int GetKeyState(int vKey);

        // Fields, constants, and structures used by the keyboard hook.
        int hookHandle = 0;
        HookProc cb = null;

        public const int WH_KEYBOARD = 2;

        public const int HC_ACTION = 0;
        public const int HC_NOREMOVE = 3;

        public const int VK_CONTROL = 0x11;
        public const int VK_LWIN = 0x5B;
        public const int VK_RWIN = 0x5C;
        public const int VK_APPS = 0x5D;
        public const int VK_LSHIFT = 0xA0;
        public const int VK_RSHIFT = 0xA1;
        public const int VK_LCONTROL = 0xA2;
        public const int VK_RCONTROL = 0xA3;
        public const int VK_LMENU = 0xA4;
        public const int VK_RMENU = 0xA5;
        public const int VK_BROWSER_BACK = 0xA6;
        public const int VK_BROWSER_FORWARD = 0xA7;
        public const int VK_BROWSER_REFRESH = 0xA8;
        public const int VK_BROWSER_STOP = 0xA9;
        public const int VK_BROWSER_SEARCH = 0xAA;
        public const int VK_VOLUME_MUTE = 0xAD;
        public const int VK_VOLUME_DOWN = 0xAE;
        public const int VK_VOLUME_UP = 0xAF;
        public const int VK_MEDIA_NEXT_TRACK = 0xB0;
        public const int VK_MEDIA_PREV_TRACK = 0xB1;
        public const int VK_MEDIA_STOP = 0xB2;
        public const int VK_MEDIA_PLAY_PAUSE = 0xB3;
        public const int KF_UP = 0x8000;
        public const long KB_TRANSITION_FLAG = 0x80000000;
        public const int VK_W = 0x57;

        // Keyboard hook delegate
        public delegate int HookProc(int code, int wparam, int lparam);
        public int Proc(int code, int wparam, int lparam)
        {
            if (code == HC_ACTION)
            {
                switch (wparam)
                {
                    case VK_BROWSER_BACK:
                        // Handle Back keyboard button here.
                        textBox1.Text += "Browser Back key caught" +
                                         Environment.NewLine;
                        break;
                    case VK_BROWSER_FORWARD:
                        // Handle Forward keyboard button here.
                        textBox1.Text += "Browser Forward key caught" +
                                         Environment.NewLine;
                        break;
                    case VK_BROWSER_REFRESH:
                        // Handle Refresh keyboard button here.
                        textBox1.Text += "Browser Refresh key caught" +
                                         Environment.NewLine;
                        break;
                    case VK_BROWSER_STOP:
                        // Handle Stop keyboard button here.
                        textBox1.Text += "Browser Stop key caught" +
                                         Environment.NewLine;
                        break;
                    case VK_BROWSER_SEARCH:
                        // Handle Search keyboard button here.
                        textBox1.Text += "Browser Search key caught" +
                                         Environment.NewLine;
                        break;
                    case VK_VOLUME_MUTE:
                        // Handle Mute keyboard button here.
                        textBox1.Text += "Volume Mute key caught" +
                                         Environment.NewLine;
                        break;
                    case VK_VOLUME_DOWN:
                        // Handle Volume - keyboard button here.
                        textBox1.Text += "Volume Down key caught" +
                                         Environment.NewLine;
                        break;
                    case VK_VOLUME_UP:
                        // Handle Volume + keyboard button here.
                        textBox1.Text += "Volume Up key caught" +
                                         Environment.NewLine;
                        break;
                    case VK_MEDIA_NEXT_TRACK:
                        // Handle Next Track keyboard button here.
                        textBox1.Text += "Media Next Track key caught" +
                                         Environment.NewLine;
                        break;
                    case VK_MEDIA_PREV_TRACK:
                        // Handle Previous Track keyboard button here.
                        textBox1.Text += "Media Previous Track key caught" +
                                         Environment.NewLine;
                        break;
                    case VK_MEDIA_STOP:
                        // Handle Stop keyboard button here.
                        textBox1.Text += "Media Stop key caught" +
                                         Environment.NewLine;
                        break;
                    case VK_MEDIA_PLAY_PAUSE:
                        // Handle PLAY keyboard button here.
                        textBox1.Text += "Media Play/Pause key caught" +
                                         Environment.NewLine;
                        break;
                }
            }
            return (CallNextHookEx(hookHandle, code, wparam, lparam));
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            wmp.PlayStateChange +=
                new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(Player_PlayStateChange);
            wmp.MediaError +=
                new WMPLib._WMPOCXEvents_MediaErrorEventHandler(Player_MediaError);

                   }

I don't get any errors, but it doesn't appear to work. Any ideas?

WHEELS
AnswerRe: Detecting music keys from keyboard in winform app Pin
Covean5-Jan-10 3:11
Covean5-Jan-10 3:11 
GeneralRe: Detecting music keys from keyboard in winform app Pin
Wheels0125-Jan-10 3:18
Wheels0125-Jan-10 3:18 
GeneralRe: Detecting music keys from keyboard in winform app Pin
Covean5-Jan-10 3:51
Covean5-Jan-10 3:51 
GeneralRe: Detecting music keys from keyboard in winform app Pin
Wheels0125-Jan-10 4:09
Wheels0125-Jan-10 4:09 
GeneralRe: Detecting music keys from keyboard in winform app Pin
Covean5-Jan-10 4:16
Covean5-Jan-10 4:16 
GeneralRe: Detecting music keys from keyboard in winform app Pin
Wheels0125-Jan-10 4:58
Wheels0125-Jan-10 4:58 
GeneralRe: Detecting music keys from keyboard in winform app Pin
Saksida Bojan5-Jan-10 6:09
Saksida Bojan5-Jan-10 6:09 
QuestionOutlookAddin Pin
Md. Marufuzzaman5-Jan-10 1:31
professionalMd. Marufuzzaman5-Jan-10 1:31 
QuestionHow validate c# DataGridView Cell to accept only Alphabet characters upper, lower and Numeric Pin
Member 11161155-Jan-10 0:33
Member 11161155-Jan-10 0:33 
QuestionFaster Pin
sanforjackass5-Jan-10 0:28
sanforjackass5-Jan-10 0:28 
AnswerRe: Faster [modified] Pin
Saksida Bojan5-Jan-10 2:01
Saksida Bojan5-Jan-10 2:01 
AnswerRe: Faster Pin
Rob Philpott5-Jan-10 2:12
Rob Philpott5-Jan-10 2:12 
GeneralRe: Faster Pin
harold aptroot5-Jan-10 3:32
harold aptroot5-Jan-10 3:32 
QuestionProper way to determine the colors of controls? Pin
arnold_w5-Jan-10 0:20
arnold_w5-Jan-10 0:20 
AnswerRe: Proper way to determine the colors of controls? Pin
petercrab5-Jan-10 0:32
petercrab5-Jan-10 0:32 
GeneralRe: Proper way to determine the colors of controls? Pin
arnold_w5-Jan-10 0:36
arnold_w5-Jan-10 0:36 
GeneralRe: Proper way to determine the colors of controls? Pin
Saksida Bojan5-Jan-10 1:54
Saksida Bojan5-Jan-10 1:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.