Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
罗技G-KEY宏SDK(C#):can';当我按下鼠标按钮时,我无法输入配置文件_C#_Logitech - Fatal编程技术网

罗技G-KEY宏SDK(C#):can';当我按下鼠标按钮时,我无法输入配置文件

罗技G-KEY宏SDK(C#):can';当我按下鼠标按钮时,我无法输入配置文件,c#,logitech,C#,Logitech,SDK链接: 它可以在LGS中创建配置文件,但如果我在GkeySDKCallback()中调试,当我按下鼠标按钮时,它无法输入配置文件 我就此向Logitech开发支持部门发送了一封电子邮件,但目前尚未收到任何回复。 这是我的代码[2个文件] Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; u

SDK链接:

它可以在LGS中创建配置文件,但如果我在GkeySDKCallback()中调试,当我按下鼠标按钮时,它无法输入配置文件

我就此向Logitech开发支持部门发送了一封电子邮件,但目前尚未收到任何回复。 这是我的代码[2个文件]

Form1.cs

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.Windows.Forms;

namespace Logitceh
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        bool usingCallback = false;
        private void Form1_Load(object sender, EventArgs e)
        {
            this.TransparencyKey = Color.Red;
            this.BackColor = Color.Red;
            Start();
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            OnDestroy();
        }

        void Start()
        {
            usingCallback = true; 
            if (usingCallback)
            {
                LogitechGSDK.logiGkeyCB cbInstance = new
                LogitechGSDK.logiGkeyCB(this.GkeySDKCallback);
                LogitechGSDK.LogiGkeyInitWithoutContext(cbInstance);
            }
            else
            {
                LogitechGSDK.LogiGkeyInitWithoutCallback();
            }
        }



        void OnUpdate()
        {
            if (!usingCallback)
            {
                for (int index = 6; index <= LogitechGSDK.LOGITECH_MAX_MOUSE_BUTTONS; index++)
                {
                    if (LogitechGSDK.LogiGkeyIsMouseButtonPressed(index) == 1)
                    {
                        //  Code    to  handle  what    happens on  gkey    pressed on  mouse
                    }
                }
                for (int index = 1; index <= LogitechGSDK.LOGITECH_MAX_GKEYS; index++)
                {
                    for (int mKeyIndex = 1; mKeyIndex <= LogitechGSDK.LOGITECH_MAX_M_STATES;
            mKeyIndex++)
                    {
                        if (LogitechGSDK.LogiGkeyIsKeyboardGkeyPressed(index, mKeyIndex) == 1)
                        {
                            //  Code    to  handle  what    happens on  gkey    pressed on  keyboard/headset
                        }
                    }
                }
            }
        }

        void GkeySDKCallback(LogitechGSDK.GkeyCode gKeyCode, String gKeyOrButtonString, IntPtr context)
        {
            if (gKeyCode.keyDown == 1)
            {
                if (gKeyCode.mouse == 1)
                {
                    //  Code    to  handle  what    happens on  gkey    released    on  mouse
                }
                else
                {
                    //  Code    to  handle  what    happens on  gkey released   on  keyboard/headset
                }

            }
            else
            {
                if (gKeyCode.mouse == 1)
                {
                    //  Code    to  handle  what    happens on  gkey    pressed on  mouse
                }
                else
                {
                    //  Code    to  handle  what    happens on  gkey    pressed on  keyboard
                }
            }
        }
        void OnDestroy()
        {
            //Free G-Keys   SDKs    before  quitting    the game
            LogitechGSDK.LogiGkeyShutdown();
        }
    }

}
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Specialized;
using System;
public class LogitechGSDK
{
    //G-KEY SDK
    public const int LOGITECH_MAX_MOUSE_BUTTONS = 20;
    public const int LOGITECH_MAX_GKEYS = 29;
    public const int LOGITECH_MAX_M_STATES = 3;
    [StructLayout(LayoutKind.Sequential, Pack = 2)]
    public struct GkeyCode
    {
        public ushort complete;
        //  index   of  the G   key or  mouse   button, for example,    6   for G6  or  Button  6
        public int keyIdx
        {
            get
            {
                return complete & 255;
            }
        }
        //  key up  or  down,   1   is  down,   0   is  up
        public int keyDown
        {
            get
            {
                return (complete >> 8) & 1;
            }
        }
        //  mState  (1, 2   or  3   for M1, M2  and M3)
        public int mState
        {
            get
            {
                return (complete >> 9) & 3;
            }
        }
        //  indicate    if  the Event   comes   from    a   mouse,  1   is  yes,    0   is  no.
        public int mouse
        {
            get
            {
                return (complete >> 11) & 15;
            }
        }
        //  reserved1
        public int reserved1
        {
            get
            {
                return (complete >> 15) & 1;
            }
        }
        //  reserved2
        public int reserved2
        {
            get
            {
                return (complete >> 16) & 131071;
            }
        }
    }
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    public delegate void logiGkeyCB(GkeyCode gkeyCode,
    [MarshalAs(UnmanagedType.LPWStr)]String gkeyOrButtonString, IntPtr context);    //  ??
    [DllImport(@"C:/DLL/LogitechGkeyEnginesWrapper", CharSet = CharSet.Unicode,
    CallingConvention = CallingConvention.Cdecl)]
    public static extern int LogiGkeyInitWithoutCallback();
    [DllImport(@"C:/DLL/LogitechGkeyEnginesWrapper", CharSet = CharSet.Unicode,
    CallingConvention = CallingConvention.Cdecl)]
    public static extern int LogiGkeyInitWithoutContext(logiGkeyCB gkeyCB);
    [DllImport(@"C:/DLL/LogitechGkeyEnginesWrapper", CharSet = CharSet.Unicode,
    CallingConvention = CallingConvention.Cdecl)]
    public static extern int LogiGkeyIsMouseButtonPressed(int buttonNumber);
    [DllImport(@"C:/DLL/LogitechGkeyEnginesWrapper", CharSet = CharSet.Unicode,
    CallingConvention = CallingConvention.Cdecl)]
    public static extern IntPtr LogiGkeyGetMouseButtonString(int buttonNumber);
    public static String LogiGkeyGetMouseButtonStr(int buttonNumber)
    {
        String str =
        Marshal.PtrToStringUni(LogiGkeyGetMouseButtonString(buttonNumber));
        return str;
    }
    [DllImport(@"C:/DLL/LogitechGkeyEnginesWrapper", CharSet = CharSet.Unicode,
    CallingConvention = CallingConvention.Cdecl)]
    public static extern int LogiGkeyIsKeyboardGkeyPressed(int gkeyNumber, int
    modeNumber);
    [DllImport(@"C:/DLL/LogitechGkeyEnginesWrapper")]
    private static extern IntPtr LogiGkeyGetKeyboardGkeyString(int gkeyNumber, int
    modeNumber);
    public static String LogiGkeyGetKeyboardGkeyStr(int gkeyNumber, int modeNumber)
    {
        String str =
        Marshal.PtrToStringUni(LogiGkeyGetKeyboardGkeyString(gkeyNumber, modeNumber));
        return str;
    }
    [DllImport(@"C:/DLL/LogitechGkeyEnginesWrapper", CharSet = CharSet.Unicode,
    CallingConvention = CallingConvention.Cdecl)]
    public static extern void LogiGkeyShutdown();
}

你不需要用“+=”注册回调事件吗?我根据Logitech SDK编写LogitechGSDK.csI下载了SDK并阅读了c#Instructions.pdf。确保执行步骤3(32位)或步骤4(64位)并结束文档。我无法从你的评论中判断问题是设备还是软件。可能是设备安装不正确。因此,我会使用设备管理器检查设备是否已安装,而不是显示问题的黄色。我还会通过单步执行代码(或添加断点)确保您输入了所有方法。如果使用VS menu Debug:BRAKALL卡在其中一个SDK方法中,则会显示代码停止的位置。设备已安装,而不是黄色感叹号图标。您需要进行更多调试,以查看软件是否正在运行所有配置代码。