Example #1
0
        public static uint joyGetPosEx(uint uJoyID, ref JOYINFOEX pji)
        {
            uint ret = MMSYSERR_ERROR;

            if (status_winmm != DllStatus.NotFound)
            {
                try {
                    ret = __joyGetPosEx(uJoyID, ref pji);
                } catch (DllNotFoundException ex) {
                    status_winmm = DllStatus.NotFound;
                }
            }
            return(ret);
        }
Example #2
0
 public static uint joyGetPosEx( uint uJoyID, ref JOYINFOEX pji ) {
     uint ret = MMSYSERR_ERROR;
     if ( status_winmm != DllStatus.NotFound ) {
         try {
             ret = __joyGetPosEx( uJoyID, ref pji );
         } catch ( DllNotFoundException ex ) {
             status_winmm = DllStatus.NotFound;
         }
     }
     return ret;
 }
Example #3
0
 private static extern uint __joyGetPosEx( uint uJoyID, ref JOYINFOEX pji );
Example #4
0
 private static extern uint __joyGetPosEx(uint uJoyID, ref JOYINFOEX pji);
Example #5
0
        public static bool JoyGetStatus(int index_, out byte[] buttons, out int pov)
        {
            if (!s_initialized)
            {
                pov     = -1;
                buttons = new byte[0];
                return(false);
            }
            if (s_num_joydev == 0 || index_ < 0 || (int)s_num_joydev <= index_)
            {
                pov     = -1;
                buttons = new byte[0];
                return(false);
            }
            int index = s_joy_available[index_];
            int len   = (int)s_joycaps[index].wNumButtons;

            buttons = new byte[len];
            pov     = -1;
            JOYINFOEX ji_ex = new JOYINFOEX();
            JOYCAPSW  jcs   = s_joycaps[index];

            ji_ex.dwSize = (ushort)Marshal.SizeOf(ji_ex);
            if ((jcs.wCaps & win32.JOYCAPS_HASPOV) == win32.JOYCAPS_HASPOV)
            {
                ji_ex.dwFlags = win32.JOY_RETURNPOV | win32.JOY_RETURNBUTTONS;
            }
            else
            {
                ji_ex.dwFlags = win32.JOY_RETURNBUTTONS | win32.JOY_RETURNX | win32.JOY_RETURNY;
            }

            if (s_joy_attatched[index])
            {
                uint ret_getpos = win32.joyGetPosEx((uint)index, ref ji_ex);
                if (ret_getpos == win32.JOYERR_NOERROR)
                {
                    if ((jcs.wCaps & win32.JOYCAPS_HASPOV) == win32.JOYCAPS_HASPOV)
                    {
                        pov = (int)ji_ex.dwPOV;
                        if ((0xffff & ji_ex.dwPOV) == 0xffff)
                        {
                            pov = -1;
                        }
                    }
                    else
                    {
                        int flag = 0;
                        if (ji_ex.dwXpos < jcs.wXmin + (jcs.wXmax - jcs.wXmin) / 3)
                        {
                            flag = flag | 1;
                        }
                        if (ji_ex.dwYpos < jcs.wYmin + (jcs.wYmax - jcs.wYmin) / 3)
                        {
                            flag = flag | 2;
                        }
                        if (ji_ex.dwXpos > jcs.wXmax - (jcs.wXmax - jcs.wXmin) / 3)
                        {
                            flag = flag | 4;
                        }
                        if (ji_ex.dwYpos > jcs.wYmax - (jcs.wYmax - jcs.wYmin) / 3)
                        {
                            flag = flag | 8;
                        }
                        if (flag == 1)
                        {
                            pov = 27000;           //左
                        }
                        if (flag == 2)
                        {
                            pov = 0;           //上
                        }
                        if (flag == 4)
                        {
                            pov = 9000;           //右
                        }
                        if (flag == 8)
                        {
                            pov = 18000;           //下
                        }
                        if (flag == 3)
                        {
                            pov = 31500;           //左上
                        }
                        if (flag == 6)
                        {
                            pov = 4500;           //右上
                        }
                        if (flag == 12)
                        {
                            pov = 13500;            //右下
                        }
                        if (flag == 9)
                        {
                            pov = 22500;           //左下
                        }
                    }
                    for (int i = 0; i < len && i < jcs.wNumButtons; i++)
                    {
                        buttons[i] = (((uint)ji_ex.dwButtons & _BTN[i]) != 0x0) ? (byte)0x80 : (byte)0x00;
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Example #6
0
        public static boolean JoyGetStatus( int index_, out byte[] buttons, out int pov ) {
            if ( !s_initialized ) {
                pov = -1;
                buttons = new byte[0];
                return false;
            }
            if ( s_num_joydev == 0 || index_ < 0 || (int)s_num_joydev <= index_ ) {
                pov = -1;
                buttons = new byte[0];
                return false;
            }
            int index = s_joy_available[index_];
            int len = (int)s_joycaps[index].wNumButtons;
            buttons = new byte[len];
            pov = -1;
            JOYINFOEX ji_ex = new JOYINFOEX();
            JOYCAPSW jcs = s_joycaps[index];
            ji_ex.dwSize = (ushort)Marshal.SizeOf( ji_ex );
            if ( (jcs.wCaps & win32.JOYCAPS_HASPOV) == win32.JOYCAPS_HASPOV ) {
                ji_ex.dwFlags = win32.JOY_RETURNPOV | win32.JOY_RETURNBUTTONS;
            } else {
                ji_ex.dwFlags = win32.JOY_RETURNBUTTONS | win32.JOY_RETURNX | win32.JOY_RETURNY;
            }

            if ( s_joy_attatched[index] ) {
                uint ret_getpos = win32.joyGetPosEx( (uint)index, ref ji_ex );
                if ( ret_getpos == win32.JOYERR_NOERROR ) {
                    if ( (jcs.wCaps & win32.JOYCAPS_HASPOV) == win32.JOYCAPS_HASPOV ) {
                        pov = (int)ji_ex.dwPOV;
                        if ( (0xffff & ji_ex.dwPOV) == 0xffff ) {
                            pov = -1;
                        }
                    } else {
                        int flag = 0;
                        if ( ji_ex.dwXpos < jcs.wXmin + (jcs.wXmax - jcs.wXmin) / 3 ) flag = flag | 1;
                        if ( ji_ex.dwYpos < jcs.wYmin + (jcs.wYmax - jcs.wYmin) / 3 ) flag = flag | 2;
                        if ( ji_ex.dwXpos > jcs.wXmax - (jcs.wXmax - jcs.wXmin) / 3 ) flag = flag | 4;
                        if ( ji_ex.dwYpos > jcs.wYmax - (jcs.wYmax - jcs.wYmin) / 3 ) flag = flag | 8;
                        if ( flag == 1 ) pov = 27000;//左
                        if ( flag == 2 ) pov = 0;//上
                        if ( flag == 4 ) pov = 9000;//右
                        if ( flag == 8 ) pov = 18000;//下
                        if ( flag == 3 ) pov = 31500;//左上
                        if ( flag == 6 ) pov = 4500;//右上
                        if ( flag == 12 ) pov = 13500;//右下
                        if ( flag == 9 ) pov = 22500;//左下
                    }
                    for ( int i = 0; i < len && i < jcs.wNumButtons; i++ ) {
                        buttons[i] = (((uint)ji_ex.dwButtons & _BTN[i]) != 0x0) ? (byte)0x80 : (byte)0x00;
                    }
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }