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


    Write your reply...

    Similar threads

    Windows Notepad works fine nothing special involved.
    Windows Notepad works fine nothing special involved.
    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
    3
    Views
    564
    I did a check of MP 1.36 x64 on Win11 and I can confirm, that the TV server correctly detects running MediaPortal.exe process.
    I did a check of MP 1.36 x64 on Win11 and I can confirm, that the TV server correctly detects running MediaPortal.exe process.
    Hi, I am using MP in a client-only setup including DVB-S card for over 10 years now. And regularily scheduling records waking up...
    Replies
    9
    Views
    1K
    How do you add a new selection to the TV Guide Rows option in the BasicHome Editor in DWHD? Id like to add an option for 8 Rows. Which xmls should I be looking at to change.? Thanks!
    How do you add a new selection to the TV Guide Rows option in the BasicHome Editor in DWHD? Id like to add an option for 8 Rows...
    How do you add a new selection to the TV Guide Rows option in the BasicHome Editor in DWHD? Id like to add an option for 8 Rows...
    Replies
    0
    Views
    218
    Well, I had already recognized your problem, but I still wanted to point out the basic connections once again. Unfortunately, I don't have a fundamentally different solution for you, but with this approach you should achieve your goal. ;) The idea of first setting the current genre colors with the defines is certainly a good one, as...
    Well, I had already recognized your problem, but I still wanted to point out the basic connections once again. Unfortunately, I...
    Good afternoon, Does anyone know a way of referencing the genre colour of the currently selected item in the TV Guide. We are all...
    Replies
    4
    Views
    460
    Sorry, I mixed something :sleep: works now - Thanks!
    Sorry, I mixed something :sleep: works now - Thanks!
    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
    13
    Views
    2K
    Top Bottom