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

    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
    873
    It is present, but not with that name. It is called Scheduler, viz: Interesting. I had never noticed that when the "command" is "ACTION", the "cmdproperty" is the actual window id, but it makes sense that it is. Try this for yourself. First backup your working profile for the remote, then in the "Mapping" panel make a change to...
    It is present, but not with that name. It is called Scheduler, viz: Interesting. I had never noticed that when the "command" is...
    I would like to be able to go directly to the Scheduled recordings window without having to first go to the home menu. I saw this...
    Replies
    1
    Views
    1K
    I think 1.38 is easier, it's a minor addition, judging by the lack of bugs, 1.39 is still a long way off. Ideally, the TuningParameters settings would be moved to MPE1, along with all the skins. Then any minor fixes could be updated quickly.
    I think 1.38 is easier, it's a minor addition, judging by the lack of bugs, 1.39 is still a long way off. Ideally, the...
    Hello and good morning, atm I´m gonna try to install my new MP2 Server with a hybrid solution DVB-T2 and MagentaTV. For DVB-T2 I...
    Replies
    9
    Views
    2K
    This is for the tvserver, the iptv part. It used to only support m3u files containing all the channels, but now you can use a m3u8 too. Usually you get an m3u8 from your iptv provider, but there are also some that can be found on the internet
    This is for the tvserver, the iptv part. It used to only support m3u files containing all the channels, but now you can use a m3u8...
    Hi! I read about [MP1-5236] - Add support for m3u8 files, but I can't find info on how to use this. So, where and how can I use...
    Replies
    1
    Views
    846
    Top Bottom