Beispiel #1
0
        // Token: 0x06000117 RID: 279 RVA: 0x0000C43C File Offset: 0x0000A63C
        private static IntPtr HookProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr returnCode = KeyboardInput.CallWindowProc(KeyboardInput.prevWndProc, hWnd, msg, wParam, lParam);

            if (msg <= 135u)
            {
                if (msg != 81u)
                {
                    if (msg == 135u)
                    {
                        returnCode = (IntPtr)(returnCode.ToInt32() | 4);
                    }
                }
                else
                {
                    KeyboardInput.ImmAssociateContext(hWnd, KeyboardInput.hIMC);
                    returnCode = (IntPtr)1;
                }
            }
            else
            {
                switch (msg)
                {
                case 256u:
                    if (KeyboardInput.KeyDown != null)
                    {
                        KeyboardInput.KeyDown(null, new KeyEventArgs((Keys)((int)wParam)));
                    }
                    break;

                case 257u:
                    if (KeyboardInput.KeyUp != null)
                    {
                        KeyboardInput.KeyUp(null, new KeyEventArgs((Keys)((int)wParam)));
                    }
                    break;

                case 258u:
                    if (KeyboardInput.CharEntered != null)
                    {
                        KeyboardInput.CharEntered(null, new CharacterEventArgs((char)((int)wParam), lParam.ToInt32()));
                    }
                    break;

                default:
                    if (msg == 641u)
                    {
                        if (wParam.ToInt32() == 1)
                        {
                            KeyboardInput.ImmAssociateContext(hWnd, KeyboardInput.hIMC);
                        }
                    }
                    break;
                }
            }
            return(returnCode);
        }
Beispiel #2
0
 public static void Initialize(GameWindow window)
 {
     if (KeyboardInput.initialized)
     {
         throw new InvalidOperationException("KeyboardInput.Initialize can only be called once!");
     }
     KeyboardInput.hookProcDelegate = new KeyboardInput.WndProc(KeyboardInput.HookProc);
     KeyboardInput.prevWndProc      = (IntPtr)KeyboardInput.SetWindowLong(window.Handle, GWL_WNDPROC, (int)Marshal.GetFunctionPointerForDelegate(KeyboardInput.hookProcDelegate));
     KeyboardInput.initialized      = true;
 }
Beispiel #3
0
 public KeyboardDispatcher(GameWindow window)
 {
     _commandInputs = new List <char>();
     _keysDown      = new List <Keys>();
     _charsEntered  = new List <char>();
     _window        = window;
     if (Game1.game1.IsMainInstance)
     {
         KeyboardInput.Initialize(window);
     }
     KeyboardInput.CharEntered += EventInput_CharEntered;
     KeyboardInput.KeyDown     += EventInput_KeyDown;
 }
Beispiel #4
0
        private static IntPtr HookProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr returnCode = CallWindowProc(prevWndProc, hWnd, msg, wParam, lParam);

            switch (msg)
            {
            case 135u:
                returnCode = (IntPtr)(returnCode.ToInt32() | 4);
                break;

            case 256u:
                if (KeyboardInput.KeyDown != null)
                {
                    KeyboardInput.KeyDown(null, new KeyEventArgs((Keys)(int)wParam));
                }
                break;

            case 257u:
                if (KeyboardInput.KeyUp != null)
                {
                    KeyboardInput.KeyUp(null, new KeyEventArgs((Keys)(int)wParam));
                }
                break;

            case 258u:
                if (KeyboardInput.CharEntered != null)
                {
                    KeyboardInput.CharEntered(null, new CharacterEventArgs((char)(int)wParam, lParam.ToInt32()));
                }
                break;

            case 641u:
                if (wParam.ToInt32() == 1)
                {
                    ImmAssociateContext(hWnd, hIMC);
                }
                break;

            case 81u:
                ImmAssociateContext(hWnd, hIMC);
                returnCode = (IntPtr)1;
                break;
            }
            return(returnCode);
        }
Beispiel #5
0
        public void ctor(GameWindow window)
        {
            _commandInputs = new List <char>();
            _keysDown      = new List <Keys>();
            _charsEntered  = new List <char>();
            _window        = window;

            new DynData <KeyboardDispatcher>(this).Set("pastedResult", "");

            // https://stackoverflow.com/questions/1121441/addeventhandler-using-reflection
            // https://stackoverflow.com/questions/11120401/creating-delegate-from-methodinfo
            EventInfo windowTextInput = typeof(GameWindow).GetEvent("TextInput", all);
            Delegate  handler         = Delegate.CreateDelegate(windowTextInput.EventHandlerType, this, "Event_TextInput");

            windowTextInput.AddEventHandler(window, handler);

            KeyboardInput.Initialize(window);
        }
Beispiel #6
0
        private static IntPtr HookProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr num = KeyboardInput.CallWindowProc(KeyboardInput.prevWndProc, hWnd, msg, wParam, lParam);

            if (msg <= 135U)
            {
                if ((int)msg != 81)
                {
                    if ((int)msg == 135)
                    {
                        num = (IntPtr)(num.ToInt32() | 4);
                    }
                }
                else
                {
                    KeyboardInput.ImmAssociateContext(hWnd, KeyboardInput.hIMC);
                    num = (IntPtr)1;
                }
            }
            else
            {
                switch (msg)
                {
                case 256:
                    // ISSUE: reference to a compiler-generated field
                    if (KeyboardInput.KeyDown != null)
                    {
                        // ISSUE: reference to a compiler-generated field
                        KeyboardInput.KeyDown((object)null, new KeyEventArgs((Keys)(int)wParam));
                        break;
                    }
                    break;

                case 257:
                    // ISSUE: reference to a compiler-generated field
                    if (KeyboardInput.KeyUp != null)
                    {
                        // ISSUE: reference to a compiler-generated field
                        KeyboardInput.KeyUp((object)null, new KeyEventArgs((Keys)(int)wParam));
                        break;
                    }
                    break;

                case 258:
                    // ISSUE: reference to a compiler-generated field
                    if (KeyboardInput.CharEntered != null)
                    {
                        // ISSUE: reference to a compiler-generated field
                        KeyboardInput.CharEntered((object)null, new CharacterEventArgs((char)(int)wParam, lParam.ToInt32()));
                        break;
                    }
                    break;

                case 641:
                    if (wParam.ToInt32() == 1)
                    {
                        KeyboardInput.ImmAssociateContext(hWnd, KeyboardInput.hIMC);
                        break;
                    }
                    break;
                }
            }
            return(num);
        }
Beispiel #7
0
 // Token: 0x0600011E RID: 286 RVA: 0x0000C545 File Offset: 0x0000A745
 public KeyboardDispatcher(GameWindow window)
 {
     KeyboardInput.Initialize(window);
     KeyboardInput.CharEntered += new CharEnteredHandler(this.EventInput_CharEntered);
     KeyboardInput.KeyDown     += new KeyEventHandler(this.EventInput_KeyDown);
 }
Beispiel #8
0
        private static IntPtr HookProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr returnCode = KeyboardInput.CallWindowProc(KeyboardInput.prevWndProc, hWnd, msg, wParam, lParam);;

            switch (msg)
            {
            case WM_GETDLGCODE:
                returnCode = (IntPtr)DLGC_WANTALLKEYS;
                break;

            case WM_CHAR:
                CharEntered?.Invoke(null, new CharacterEventArgs((char)wParam, (int)lParam));
                break;

            case WM_KEYDOWN:
                KeyDown?.Invoke(null, new KeyEventArgs((Keys)wParam));
                break;

            case WM_KEYUP:
                KeyUp?.Invoke(null, new KeyEventArgs((Keys)wParam));
                break;

            case WM_LBUTTONDOWN:
                MouseSelection.left   = (int)lParam & 0xffff;
                MouseSelection.top    = (int)lParam >> 16;
                MouseSelection.right  = MouseSelection.left;
                MouseSelection.bottom = MouseSelection.top;
                if (Game1.keyboardDispatcher.Subscriber is ITextBox)
                {
                    ITextBox textBox = Game1.keyboardDispatcher.Subscriber as ITextBox;
                    Acp      acp     = textBox.GetAcpByRange(MouseSelection);
                    if (acp.Start >= 0)
                    {
                        textBox.SetSelection(acp.Start, acp.End);
                        Console.WriteLine("ACPStart:{0},ACPEnd:{1}", acp.Start, acp.End);
                        Console.WriteLine("MouseDown:Left:{0},TOP:{1}RIGHT:{2}BOTTOM:{3}", MouseSelection.left, MouseSelection.top, MouseSelection.right, MouseSelection.bottom);
                        Selecting = true;
                    }
                }
                break;

            case WM_MOUSEMOVE:
                MouseSelection.right  = (int)lParam & 0xffff;
                MouseSelection.bottom = (int)lParam >> 16;
                if (Selecting && Game1.keyboardDispatcher.Subscriber is ITextBox)
                {
                    RECT range = new RECT();
                    range.left   = Math.Min(MouseSelection.left, MouseSelection.right);
                    range.top    = Math.Max(MouseSelection.top, MouseSelection.bottom);
                    range.right  = Math.Max(MouseSelection.left, MouseSelection.right);
                    range.bottom = Math.Min(MouseSelection.top, MouseSelection.bottom);
                    ITextBox textBox = Game1.keyboardDispatcher.Subscriber as ITextBox;
                    Acp      acp     = textBox.GetAcpByRange(range);
                    if (acp.Start >= 0)
                    {
                        textBox.SetSelection(acp.Start, acp.End);
                        textBox.SetSelState(MouseSelection.left > MouseSelection.right ? SelState.SEL_AE_END : SelState.SEL_AE_START);
                        Console.WriteLine("ACPStart:{0},ACPEnd:{1}", acp.Start, acp.End);
                        Console.WriteLine("MouseMove:Left:{0},TOP:{1}RIGHT:{2}BOTTOM:{3}", MouseSelection.left, MouseSelection.top, MouseSelection.right, MouseSelection.bottom);
                    }
                }
                //handle IsMouseVisable
                returnCode = KeyboardInput.CallWindowProc(KeyboardInput.prevWndProc, hWnd, msg, wParam, lParam);
                break;

            case WM_LBUTTONUP:
                Selecting = false;
                break;

#if TSF
            case EM_GETSEL:
                if (Game1.keyboardDispatcher.Subscriber is ITextBox)
                {
                    ITextBox textBox = Game1.keyboardDispatcher.Subscriber as ITextBox;
                    Acp      acp     = textBox.GetSelection();
                    Marshal.WriteInt32(wParam, acp.Start);
                    Marshal.WriteInt32(lParam, acp.End);
                }
                break;

            case EM_SETSEL:
                if (Game1.keyboardDispatcher.Subscriber is ITextBox)
                {
                    ITextBox textBox = Game1.keyboardDispatcher.Subscriber as ITextBox;
                    textBox.SetSelection((int)wParam, (int)lParam);
                }
                break;

            case EM_REPLACESEL:
                if (Game1.keyboardDispatcher.Subscriber is ITextBox)
                {
                    ITextBox textBox = Game1.keyboardDispatcher.Subscriber as ITextBox;
                    textBox.ReplaceSelection(Marshal.PtrToStringAuto(lParam));
                }
                break;

            case TF_GETSELSTATE:
                if (Game1.keyboardDispatcher.Subscriber is ITextBox)
                {
                    ITextBox textBox = Game1.keyboardDispatcher.Subscriber as ITextBox;
                    returnCode = (IntPtr)textBox.GetSelState();
                }
                break;

            case TF_GETTEXT:
                if (Game1.keyboardDispatcher.Subscriber is ITextBox)
                {
                    ITextBox textBox = Game1.keyboardDispatcher.Subscriber as ITextBox;
                    var      text    = textBox.GetText();
                    Marshal.Copy(text.ToCharArray(), 0, wParam, Math.Min(text.Length, (int)lParam));
                }
                break;

            case TF_GETTEXTLENGTH:
                if (Game1.keyboardDispatcher.Subscriber is ITextBox)
                {
                    ITextBox textBox = Game1.keyboardDispatcher.Subscriber as ITextBox;
                    returnCode = (IntPtr)textBox.GetTextLength();
                }
                break;

            case TF_GETTEXTEXT:
                if (Game1.keyboardDispatcher.Subscriber is ITextBox)
                {
                    ITextBox textBox = Game1.keyboardDispatcher.Subscriber as ITextBox;
                    Acp      acp     = (Acp)Marshal.PtrToStructure(lParam, typeof(Acp));
                    RECT     rect    = textBox.GetTextExt(acp);
                    MapWindowPoints(Game1.game1.Window.Handle, (IntPtr)0, ref rect, 2); //to screen coord
                    Marshal.StructureToPtr(rect, wParam, false);                        //text ext

                    returnCode = (IntPtr)0;                                             //if the rect clipped
                }
                break;

            case TF_QUERYINSERT:
                if (Game1.keyboardDispatcher.Subscriber is ITextBox)
                {
                    ITextBox textBox = Game1.keyboardDispatcher.Subscriber as ITextBox;
                    Acp      acp     = (Acp)Marshal.PtrToStructure(wParam, typeof(Acp));
                    textBox.QueryInsert(acp, (uint)lParam);
                    Marshal.StructureToPtr(acp, wParam, false);
                }
                break;

            case WM_KILLFOCUS:
                Game1.tsf.TerminateComposition();
                break;
#endif
            default:
                break;
            }
            return(returnCode);
        }
 public KeyboardDispatcher(GameWindow window)
 {
     KeyboardInput.Initialize(window);
     KeyboardInput.CharEntered += EventInput_CharEntered;
     KeyboardInput.KeyDown     += EventInput_KeyDown;
 }