2020-02-20 19:13:58

Hello,
I have been fighting with it for some time now, but something aint right here. When I press Win+Shift+Escape nothing happens, and something should happen. As far as I know, XOR operator is used to concatenate multiple modifiers. Code below:
using radio42;
using YoutubeExplode;
using YoutubeExplode.Models;
using YoutubeExplode.Models.MediaStreams;
using DavyKager;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Un4seen.Bass;
namespace InviTube
{
    public partial class WND_Prefs : Form
    {
        [DllImport("user32.dll")]
        public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
        #region Constants
        private const string EMail = "";
        private const string RegistrationKey = "";
        private const int InviModifier = (int)Keys.LWin |(int)Keys.LShiftKey;
        #endregion
        public WND_Prefs()
        {
            InitializeComponent();
            BassNet.Registration(EMail, RegistrationKey);
            RegisterHotKey(this.Handle, (int)KeyboardShortcuts.ExitApplication, InviModifier, (int)Keys.Escape);
            this.Hide();
        }
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x0312)
            {
                int id = m.WParam.ToInt32();
                switch (id)
                {
                    case (int)KeyboardShortcuts.ExitApplication:
                            MessageBox.Show("Koty!");
                        break;
                    default:
                        break;
                }
            }
                base.WndProc(ref m);
        }
    }
}

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2020-02-20 19:30:15

Oh, and even the form does not hide, and it should

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2020-02-27 13:17:40

OK, guys... I have fixed it. I am terribly sorry to revive but need is to explain.
People on the internet say that I can cast the keys for int as modifiers. Not true. Here is the enum that need to be used for modifiers:
namespace InviTube
{
    public enum Modifiers
    {
        Alt = 0x0001,
        Control = 0x0002,
        Shift = 0x0004,
        Win = 0x0008
    }
}

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2020-02-27 17:34:40

You can probably cast to int, but you probably are using ints with the wrong values.  I can't tell for sure with as little code as you pasted because I can't find the values of the ints you are using there.

The xor operator is actually or, and the trick works because each of the values in the enum in post 3 have one bit set.  If you have a bunch of values with one bit set, often called flags, you can combine the flags with or and tell if flags are set with and, that is:

modifiers = ctrl | alt | shift
has_shift = modifiers & shift

But this only works with powers of 2.


The issue probably isn't that you've cast to an int, because the raw Win32 functions only take ints.  The issue is almost certainly that that function expects flags, not key constants, and you're combining key constants.

If you haven't, the way to troubleshoot these issues is to find and read the MSDN pages on these functions.

Also, if you're going to use window messages, don't compare directly to the hex value of the window message.  Find the constant on MSDN and give it a name.  Otherwise no one will be able to tell if it's right because it's just a magic number.

My Blog
Twitter: @ajhicks1992

2020-02-27 20:40:19

I know, thats what I did. Problem solved.

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com