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

    Yes, all compatible with x64 ;)
    Yes, all compatible with x64 ;)
    Hi folks, for all those who would like to enjoy Mediaportal on the Titanskin, I have now adapted the well-known MP games package...
    Replies
    7
    Views
    1K
    It's getting weirder..... If I remove all the IP cards in the TVServer setup and then add them back I can scan the M3u and tune the stations but if I rescan it on the same card it just keeps updating the 1 channel. My brain is melting.........
    It's getting weirder..... If I remove all the IP cards in the TVServer setup and then add them back I can scan the M3u and tune the...
    Having great fun with this still. I have a fairly good PC setup, Ryzen 5 8500g, Msi Pro 650M-P with 32GB of RAM with a TBS 6281 and...
    Replies
    2
    Views
    253
    Ran into this problem following an otherwise sucessful upgrade from MP 1.34 x64 to MP 1.35 x64 the CEC Remote plugin which I use just to control volume and standby, will no longer put my devices (TV & AVR) to sleep when the HTPC is put in standby. Also when I wake up the HTPC MP closes or crashes (not sure which) as per the example in...
    Ran into this problem following an otherwise sucessful upgrade from MP 1.34 x64 to MP 1.35 x64 the CEC Remote plugin which I use...
    Ran into this problem following an otherwise sucessful upgrade from MP 1.34 x64 to MP 1.35 x64 the CEC Remote plugin which I use...
    Replies
    0
    Views
    453
    Hi, yes, you are right. The official x64 1.32 is buggy. You can try a new installers from this post if you like.
    Hi, yes, you are right. The official x64 1.32 is buggy. You can try a new installers from this post if you like.
    hi, I'm setting up a new computer and have installed MP 1.3.2 after a few goes and getting all the prereqs installed, I was...
    Replies
    3
    Views
    1K
    Hello, I would like to use a media server to display various learning categories. I prefer not to use software like Kodi, as it requires extensive metadata scraping that I don't need. Is it possible to instantly access the video categories when landing on the page? I would like to display a single media page with the following...
    Hello, I would like to use a media server to display various learning categories. I prefer not to use software like Kodi, as it...
    Hello, I would like to use a media server to display various learning categories. I prefer not to use software like Kodi, as it...
    Replies
    0
    Views
    321
    Top Bottom