How to catch keypresses (1 Viewer)

pilehave

Community Skin Designer
  • Premium Supporter
  • April 2, 2008
    2,566
    521
    Hornslet
    Home Country
    Denmark Denmark
    Hi

    I would like to try and develop a plugin, mostly for fun. How can I detect which button a user presses on the keyboard?

    Regards, Mikkel
     

    jburnette

    Portal Pro
    August 24, 2006
    758
    116
    Kentucky
    Home Country
    United States of America United States of America
    In your plugin, override OnAction. Check for (action.wID==Action.ActionType.ACTION_KEY_PRESSED). Then you can cast the keystroke to a char with (char)action.m_key.KeyChar.
     

    pilehave

    Community Skin Designer
  • Premium Supporter
  • April 2, 2008
    2,566
    521
    Hornslet
    Home Country
    Denmark Denmark
    • Thread starter
    • Moderator
    • #3
    In your plugin, override OnAction. Check for (action.wID==Action.ActionType.ACTION_KEY_PRESSED). Then you can cast the keystroke to a char with (char)action.m_key.KeyChar.

    Thank you, I think I'm getting wiser :)

    But when I try to move on in my code, I keep getting this error:

    Code:
    The type or namespace name 'GUIDialogOK' could not be found (are you missing a using directive or an assembly reference?)

    In the top of my script I have this:

    Code:
    using System;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    using System.Web;
    using MediaPortal.Configuration;
    using MediaPortal.Util;
    using MediaPortal.GUI.Library;

    (The above is stolen from another plugin)

    I have added references to Core.dll, Utils.dll and RemotePlugins.dll (I think I'll need that one).

    The code that triggers the error in the debugger is this:

    Code:
            public override void OnAction(MediaPortal.GUI.Library.Action action)
            {
                char mumbojumbo = (char)action.m_key.KeyChar;
                OnButtonOne(mumbojumbo);
    
            }
    
            private void OnButtonOne(char whatever)
            {
                GUIDialogOK standbyMessage = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                standbyMessage.Reset();
                standbyMessage.SetHeading("Testing popup");
                standbyMessage.SetLine(1, "whatever...");
    
                standbyMessage.DoModal(MediaPortal.GUI.Library.GUIWindowManager.ActiveWindow);
    
    
            }

    Could you perhaps lead me on the way again? I'm quite new to this and have only done a little Visual Basic many years ago, but believe I know my way around PHP and also ASP...so should be able to learn on the way!

    Thank you.
     

    pilehave

    Community Skin Designer
  • Premium Supporter
  • April 2, 2008
    2,566
    521
    Hornslet
    Home Country
    Denmark Denmark
    • Thread starter
    • Moderator
    • #5
    Add a reference to Dialogs.dll. It's in plugins\windows\.

    Thanks. I'm getting good progress with my plugin and got the "catch keypresses" working and about 60% of the functionality. Now, this will work fine for my own purposes, since I use a remote that emulates keypresses via an external process.

    However, I would like to be able to support users with a remote that sends commands directly to MediaPortal, like thoses that uses the ever popular MCE remote. What should I look for in that case?

    I use this to catch keypresses at the moment:

    Code:
    if (action.m_key != null && action.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_KEY_PRESSED)
    {
    //Do some routines with Shift and Ctrl keys and the like...
    }

    How would a snippet like this look like, if I want to catch a press on the "Play" button on a MCE remote?

    :D
     

    Users who are viewing this thread

    Similar threads

    MP1 MP2 TVGuide Users DE
    Greetings Fellow MP'rs. Does anyone out there use tvguide.com to access TV listings..? :unsure: If so, can you advise on how it is set up for use with MediaPortal..? I havebeen using Zap2XML / GraceNote but that just died (for me alone seemingly) and I am out of listings. :( Would appreciate any help - Thanks.
    Greetings Fellow MP'rs. Does anyone out there use tvguide.com to access TV listings..? :unsure: If so, can you advise on how it...
    Greetings Fellow MP'rs. Does anyone out there use tvguide.com to access TV listings..? :unsure: If so, can you advise on how it...
    Replies
    0
    Views
    755
    I currently have two Quatros running, one connect, one duo using OTA antennae, mostly UHF fringe area, mostly cat5 local network. Hauppauge card retired long ago. I have also retired very early SD units, the Quatros seem to work much better than the older units. Go to SD's support website and download and install the windows...
    I currently have two Quatros running, one connect, one duo using OTA antennae, mostly UHF fringe area, mostly cat5 local network...
    I am currently using a Hauppauge WinTV QuadHD PCIe card on MP1 (1.37) for DVB-T, but 2 of the tuners have died. Thinking about...
    Replies
    3
    Views
    1K
    I'm running 2.5 with the WMC skin. I have .mp4 files, along with the related .srt files in the same folder. I can watch the movies just fine. In past versions of MP, like 2.4x, I could press the More Info button on my remote twice, and on the second press, an option for showing/choosing the subtitles was listed. I'd select the...
    I'm running 2.5 with the WMC skin. I have .mp4 files, along with the related .srt files in the same folder. I can watch the...
    I'm running 2.5 with the WMC skin. I have .mp4 files, along with the related .srt files in the same folder. I can watch the...
    Replies
    0
    Views
    3K
    You could use a different player that handles HDR content but thats more hassle then installing MadVR
    You could use a different player that handles HDR content but thats more hassle then installing MadVR
    I searched several days now but could only find non-working ideas and mostly based on MadVR. Is there a way to play HDR content...
    Replies
    1
    Views
    1K
    4.5 is really old. I'm not sure 4.5.5 even is a version that actually existed. You should be able to install .NET Framework 4.8.0 on Windows 7 SP1
    4.5 is really old. I'm not sure 4.5.5 even is a version that actually existed. You should be able to install .NET Framework 4.8.0...
    My TV PC is more a cast-off on older hardware (a 'Quiet PC' i5 4690, 16GB ram, 2xSSD 1xHDD, system graphics), mainly as a cheap way...
    Replies
    5
    Views
    2K
    Top Bottom