예제 #1
0
        public static async Task Execute(CallbackData data)
        {
            //достать данные из таблицы

            var flatNumber = ((TextMessage)data.Message).Text;

            var lastData = Handlers.GoogleSheetsHandler.GetFlatData(flatNumber);

            var trackingData = ViberBotTrackingData.Get(data.Message.TrackingData);

            trackingData.Data.Add(DataField.FlatNumber.ToString(), flatNumber);

            //отправить подтверждение
            var receiver = data.Sender.Id;

            var message = new KeyboardMessage
            {
                Receiver     = receiver,
                Sender       = client.BotUserData,
                Text         = $"Квартира - { flatNumber}. Предыдущие показания счетчика - {lastData}. Введите текущие показания.",
                TrackingData = ViberBotTrackingData.Build("EnterSendDataAction", "СonfirmSendDataAction", trackingData.Data),
                Keyboard     = KeyboardHandler.Cancel
            };
            await client.SendMessage(receiver, message);
        }
예제 #2
0
        public static async Task Execute(CallbackData data)
        {
            var receiver = data.Sender.Id;

            if (int.TryParse(((TextMessage)data.Message).Text, out int userValue))
            {
                //учесть данные в поле трекинга

                var trackingData = ViberBotTrackingData.Get(data.Message.TrackingData);

                var flatNumber = trackingData.Data[DataField.FlatNumber.ToString()];

                trackingData.Add(DataField.FlatValue.ToString(), userValue.ToString());

                //запросить  подтверждение
                var message = new KeyboardMessage
                {
                    Receiver     = receiver,
                    Sender       = client.BotUserData,
                    Text         = $"Для квартиры - {flatNumber}. Вы указали - {userValue}. Данные верны?",
                    TrackingData = ViberBotTrackingData.Build("СonfirmSendDataAction", "SendDataAction", trackingData.Data),
                    Keyboard     = KeyboardHandler.YesNoCancel()
                };
                await client.SendMessage(receiver, message);
            }
            else
            {
                //неверное значение
                await client.SendTextMessage(receiver, BotError.BadValue);
            }
        }
예제 #3
0
        /// <summary>
        /// Low-level keyboard hook procedure.
        /// The system calls this function every time a new keyboard input event
        /// is about to be posted into a thread input queue. The keyboard input
        /// can come from the local keyboard driver or from calls to the
        /// keybd_event function. If the input comes from a call to keybd_event,
        /// the input was "injected". However, the WH_KEYBOARD_LL hook is not
        /// injected into another process. Instead, the context switches back
        /// to the process that installed the hook and it is called in its
        /// original context. Then the context switches back to the application
        /// that generated the event.
        /// </summary>
        /// <param name="nCode">
        /// The hook code passed to the current hook procedure.
        /// When nCode equals HC_ACTION, it means that the wParam and lParam
        /// parameters contain information about a keyboard message.
        /// </param>
        /// <param name="wParam">
        /// The parameter can be one of the following messages:
        /// WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP.
        /// </param>
        /// <param name="lParam">Pointer to a KBDLLHOOKSTRUCT structure.</param>
        /// <returns></returns>
        /// <see cref="http://msdn.microsoft.com/en-us/library/ms644985.aspx"/>
        public int LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                // Marshal the KeyboardHookStruct data from the callback lParam
                KBDLLHOOKSTRUCT keyboardLLHookStruct = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));

                // Get the virtual key code from KBDLLHOOKSTRUCT.vkCode
                // http://msdn.microsoft.com/en-us/library/dd375731.aspx
                Key vkCode = (Key)keyboardLLHookStruct.vkCode;

                // Get the keyboard WM from the wParam parameter
                KeyboardMessage wmKeyboard = (KeyboardMessage)wParam;

                if (wmKeyboard == KeyboardMessage.WM_KEYUP)
                {
                    KeyUpEvent keyUp = OnKeyUp;
                    if (keyUp != null)
                    {
                        Task.Factory.StartNew(delegate() { keyUp(); });
                    }
                }
            }

            // Pass the hook information to the next hook procedure in chain
            return(NativeMethod.CallNextHookEx(hGlobalLLKeyboardHook, nCode, wParam, lParam));
        }
예제 #4
0
        public static void Process(KeyboardMessage value, Controller controller)
        {
            if ((value.VirutalKey == (int)KeyCodes.Keys.Up && value.Flags == 1) ||
                (value.VirutalKey == (int)KeyCodes.Keys.W && value.Flags == 1))
            {
                BrowserMapping.Controller.Scroll(-10);
                log.Debug($"Scroll Up");
            }

            if ((value.VirutalKey == (int)KeyCodes.Keys.Down && value.Flags == 1) ||
                (value.VirutalKey == (int)KeyCodes.Keys.S && value.Flags == 1))
            {
                BrowserMapping.Controller.Scroll(10);
                log.Debug($"Scroll Down");
            }

            if ((value.VirutalKey == (int)KeyCodes.Keys.Left && value.Flags == 1) ||
                (value.VirutalKey == (int)KeyCodes.Keys.A && value.Flags == 1))
            {
                BrowserMapping.Controller.ChangeTab(-1);
                log.Debug($"Previous Tab");
            }

            if ((value.VirutalKey == (int)KeyCodes.Keys.Right && value.Flags == 1) ||
                (value.VirutalKey == (int)KeyCodes.Keys.D && value.Flags == 1))
            {
                BrowserMapping.Controller.ChangeTab(1);
                log.Debug($"Next Tab");
            }
        }
예제 #5
0
        public static async Task Execute(CallbackData data)
        {
            // проверить есть ли запись о пользователе вообще
            //или создавать ее во время приветствия

            //отправить подтверждение
            var receiver = data.Sender.Id;

            //достать данные из таблицы
            var contactsData = Handlers.GoogleSheetsHandler.GetContactsData(data.Sender.Id);
            var trackingData = JsonConvert.DeserializeObject <ViberBotTrackingData>(data.Message.TrackingData);

            trackingData.Add(DataField.Contacts.ToString(), contactsData);

            var message = new KeyboardMessage
            {
                Receiver     = receiver,
                Sender       = client.BotUserData,
                Text         = $"Указанные контактные данные - {contactsData}. Введите номер телефона по которому можно было бы с вами связаться. Данные вводите в числовом формате без пробелов. Пример: +370123456789",
                TrackingData = ViberBotTrackingData.Build("StartSendContactsAction", "СonfirmSendContactsAction", trackingData.Data),
                Keyboard     = KeyboardHandler.Cancel
            };

            await client.SendMessage(receiver, message);
        }
예제 #6
0
        /// <summary>
        /// Low-level keyboard hook procedure.
        /// The system calls this function every time a new keyboard input event
        /// is about to be posted into a thread input queue. The keyboard input
        /// can come from the local keyboard driver or from calls to the
        /// keybd_event function. If the input comes from a call to keybd_event,
        /// the input was "injected". However, the WH_KEYBOARD_LL hook is not
        /// injected into another process. Instead, the context switches back
        /// to the process that installed the hook and it is called in its
        /// original context. Then the context switches back to the application
        /// that generated the event.
        /// </summary>
        /// <param name="nCode">
        /// The hook code passed to the current hook procedure.
        /// When nCode equals HC_ACTION, it means that the wParam and lParam
        /// parameters contain information about a keyboard message.
        /// </param>
        /// <param name="wParam">
        /// The parameter can be one of the following messages:
        /// WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP.
        /// </param>
        /// <param name="lParam">Pointer to a KBDLLHOOKSTRUCT structure.</param>
        /// <returns></returns>
        /// <see cref="http://msdn.microsoft.com/en-us/library/ms644985.aspx"/>
        public int LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                // Marshal the KeyboardHookStruct data from the callback lParam
                KBDLLHOOKSTRUCT keyboardLLHookStruct = (KBDLLHOOKSTRUCT)
                                                       Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));

                // Get the virtual key code from KBDLLHOOKSTRUCT.vkCode
                // http://msdn.microsoft.com/en-us/library/dd375731.aspx
                Keys vkCode = (Keys)keyboardLLHookStruct.vkCode;

                // Get the keyboard WM from the wParam parameter
                KeyboardMessage wmKeyboard = (KeyboardMessage)wParam;

                // Display the current mouse coordinates and the message
                String log = String.Format("Virtual-Key code: {0}  ({1})\r\n",
                                           vkCode, wmKeyboard);
                this.tbLog.AppendText(log);

                startEngagement = DateTime.Now;


                //if ((int)wmKeyboard == WM_KEYDOWN)
                //    myDevice.SetControlByID(0, myDevice.GetControlValueByID(0) == 0 ? 1 : 0);
            }

            // Pass the hook information to the next hook procedure in chain
            return(NativeMethods.CallNextHookEx(hGlobalLLKeyboardHook, nCode, wParam, lParam));
        }
예제 #7
0
        public static async Task Execute(CallbackData data)
        {
            //достать данные из таблицы
            var receiver = data.Sender.Id;
            var flats    = Handlers.GoogleSheetsHandler.CheckFlatData(data.Sender.Id);

            if (flats.Any())
            {
                var flatButtonsData = new List <string[]>();

                foreach (var flat in flats)
                {
                    flatButtonsData.Add(new string[] { flat.ToString(), flat.ToString() });
                }

                flatButtonsData.Add(new string[] { "Отмена", "Cancel" });
                //отправить подтверждение

                var message = new KeyboardMessage
                {
                    Receiver     = receiver,
                    Sender       = client.BotUserData,
                    Text         = $"Выберите номер квартиру для удаления.",
                    TrackingData = ViberBotTrackingData.Build("ConfirmDeleteFlatNumberAction", "DeleteFlatNumberAction"),
                    Keyboard     = KeyboardHandler.CustomButtons(flatButtonsData.ToArray())
                };

                await client.SendMessage(receiver, message);
            }
            else
            {
                await client.SendTextMessage(receiver, "Нет привязаных квартир.");
            }
        }
예제 #8
0
        public async Task <KeyboardMessage> GetTeams(Callback callback)
        {
            League league;

            IEnumerable <League> leagues = await _leagueRepository.GetAll(version);

            league = leagues.SingleOrDefault(x => x.Name == callback.Message.TrackingData);

            if (league == null)
            {
                league = leagues.SingleOrDefault(x => x.Name == callback.Message.Text);
            }

            var sortedTeams = league?.Teams.OrderByDescending(o => o.Position);

            var keyboardMessage = new KeyboardMessage(callback.Sender.Id, MessageConstant.CHOOSE_TEAM)
            {
                Sender = new UserBase
                {
                    Name   = MessageConstant.BOT_NAME,
                    Avatar = MessageConstant.BOT_AVATAR,
                },
                Keyboard = new Keyboard
                {
                    DefaultHeight = true,
                    Buttons       = CreateButtons(sortedTeams)
                },
                TrackingData = callback.Message.Text
            };

            return(keyboardMessage);
        }
예제 #9
0
        public static async Task Execute(CallbackData data)
        {
            //достать данные из таблицы
            var flats = Handlers.GoogleSheetsHandler.CheckFlatData(data.Sender.Id);

            if (flats.Count > 0)
            {
                //отправить подтверждение
                var receiver = data.Sender.Id;

                var message = new KeyboardMessage
                {
                    Receiver     = receiver,
                    Sender       = client.BotUserData,
                    Text         = $"Вы указывали квартиры : {String.Join(",", flats)}. Выберите действие.",
                    TrackingData = ViberBotTrackingData.Build("", "StartSetFlatNumberAction"),
                    Keyboard     = KeyboardHandler.CustomButtons(new string[][] { new string[] { "Добавить квартиру", "AddFlatNumberAction" }, new string[] { "Удалить квартиру", "ConfirmDeleteFlatNumberAction" }, new string[] { "Отмена", "Cancel" } })
                };

                await client.SendMessage(receiver, message);
            }
            else
            {
                await AddFlatNumberAction.Execute(data);
            }
        }
예제 #10
0
        public static async Task Execute(CallbackData data)
        {
            var text         = ((TextMessage)data.Message).Text;
            var receiver     = data.Sender.Id;
            var trackingData = ViberBotTrackingData.Get(data.Message.TrackingData);

            if (text == "no")
            {
                await StartSetFlatNumberAction.Execute(data);

                return;
            }
            else if (text == "yes")
            {
                var flatNumber = trackingData.Data[DataField.FlatNumber.ToString()];

                //сохранить в таблицу
                Handlers.GoogleSheetsHandler.AddUserFlatNumber(flatNumber, data.Sender);

                await client.SendTextMessage(receiver, "Данные успешно сохранены.");
            }
            else
            {
                var message = new KeyboardMessage
                {
                    Receiver     = receiver,
                    Sender       = client.BotUserData,
                    Text         = $"Выберите действи из списка.",
                    TrackingData = ViberBotTrackingData.Build("SetFlatNumberAction", "SetFlatNumberAction", trackingData.Data),
                    Keyboard     = KeyboardHandler.YesNoCancel()
                };

                await client.SendMessage(receiver, message);
            }
        }
예제 #11
0
        private int LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                KBDLLHOOKSTRUCT a = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));

                KeyboardMessage wmMouse = (KeyboardMessage)wParam;
                if (wmMouse == KeyboardMessage.WM_KEYDOWN || wmMouse == KeyboardMessage.WM_SYSKEYDOWN)
                {
                    if (a.vkCode == (int)action_button_keyboard)
                    {
                        if (key_hook_handled == false)
                        {
                            key_hook_handled = true;
                            on_key_down();
                        }
                        return(pass_message ? NativeMethods.CallNextHookEx(_hGlobalLlHook, nCode, wParam, lParam) : 1);
                    }
                }
                else if (wmMouse == KeyboardMessage.WM_KEYUP || wmMouse == KeyboardMessage.WM_SYSKEYUP)
                {
                    if (a.vkCode == (int)action_button_keyboard)
                    {
                        key_hook_handled = false;
                        on_key_up();
                        return(pass_message ? NativeMethods.CallNextHookEx(_hGlobalLlHook, nCode, wParam, lParam) :1);
                    }
                }
            }
            return(NativeMethods.CallNextHookEx(_hGlobalLlHook, nCode, wParam, lParam));
        }
예제 #12
0
            private Message[] getOutput()
            {
                Position myPos     = new Position();
                Actions  myActions = new Actions();

                myPos.setPosition("ABSOLUTE", 3, 4);
                MouseMessage myMessage = new MouseMessage();

                myMessage.player   = "1";
                myMessage.position = myPos;
                myMessage.action   = "PRESSED";
                myMessage.payload  = "PAYLOAD";
                List <Keys> KeysEntered = new List <Keys>();

                KeysEntered.Add(new Keys('a'));
                KeysEntered.Add(new Keys("Right"));
                KeysEntered.Add(new Keys('b'));

                myActions.setActions("PRESSED", "PAYLOAD", KeysEntered.ToArray());
                Actions mySecondActions = new Actions();

                mySecondActions.setActions("RELEASED", "PAYLOAD12", KeysEntered.ToArray());
                KeyboardMessage myKeyboardMessage = new KeyboardMessage();

                myKeyboardMessage.player  = "1";
                myKeyboardMessage.actions = new Actions[] { myActions, mySecondActions };
                return(new Message[] { myKeyboardMessage, myMessage });
            }
예제 #13
0
 private async Task ListenAsync(short channel)
 {
     bool listening = true;
     while (listening)
     {
         var result = await Client.ReceiveAsync();
         var message = Messaging.ReceiveMessage(result.Buffer);
         switch (message.Type)
         {
             case MessageType.Disconnect:
             case MessageType.Terminate:
                 IsConnected = false;
                 await EndConnection(channel, true);
                 listening = false;
                 break;
             case MessageType.Acknowledge:
                 IsConnected = true;
                 Connect?.Invoke(this, new EventArgs());
                 break;
             case MessageType.MouseMessage:
                 var mouseMessage = new MouseMessage(message.Payload);
                 MouseInput?.Invoke(this, new MouseMessageEventArgs(mouseMessage.X, mouseMessage.Y, mouseMessage.WheelDelta, mouseMessage.ScreenWidth, mouseMessage.ScreenHeight, mouseMessage.LeftButton, mouseMessage.MiddleButton, mouseMessage.RightButton, mouseMessage.FirstExtendedButton, mouseMessage.SecondExtendedButton));
                 break;
             case MessageType.KeyboardMessage:
                 var keyboardMessage = new KeyboardMessage(message.Payload);
                 KeyboardInput?.Invoke(this, new KeyboardEventArgs(keyboardMessage.IsDown, keyboardMessage.Keys));
                 break;
         }
     }
 }
		public void CreateKeyboardMessage()
		{
			var emptyMessage = new KeyboardMessage();
			Assert.IsNull(emptyMessage.PressedKeys);
			var message = new KeyboardMessage(new Key[0]);
			Assert.AreEqual(0, message.PressedKeys.Length);
		}
예제 #15
0
 public static void Process(KeyboardMessage value, Controller controller)
 {
     // {Key: 32, ScanCode: 57, Flags: Down}
     if (value.VirutalKey == 32 && value.ScanCode == 57 && value.Flags == 0)
     {
         controller.SharedState.ChangeGear(true);
     }
 }
예제 #16
0
 private int CallNextHook(int code, KeyboardMessage message, ref KeyboardState state)
 {
     if (code >= 0)
     {
         OnKeyboardHooked(new KeyboardHookedEventArgs(message, ref state));
     }
     return(CallNextHookEx(hook, code, message, ref state));
 }
예제 #17
0
        public void CreateKeyboardMessage()
        {
            var emptyMessage = new KeyboardMessage();

            Assert.IsNull(emptyMessage.PressedKeys);
            var message = new KeyboardMessage(new Key[0]);

            Assert.AreEqual(0, message.PressedKeys.Length);
        }
예제 #18
0
 public TestingAI(string playerNum)
 {
     myPos             = new Position();
     myActions         = new Actions();
     random            = new Random();
     myKeyboardMessage = new KeyboardMessage();
     myMouseMessage    = new MouseMessage();
     myPlayer          = playerNum;
 }
예제 #19
0
 public static void Process(KeyboardMessage value, Controller controller)
 {
     // {Key: 32, ScanCode: 57, Flags: Down}
     if (value.VirutalKey == 32 && value.ScanCode == 57 && value.Flags == 0)
     {
         controller.CallActivateButton(vJoyTypes.Virtual, MappedButtons.CameraEnabled, 150);
         log.Debug("Camera Enabled");
     }
 }
예제 #20
0
        public override async Task SendMessageAsync(IChatSession sess, IOutgoingMessage msg)
        {
            if (!(sess is ChatSession))
            {
                throw new Exception("Bad chat session type");
            }
            var s = sess as ChatSession;

            switch (msg.Type)
            {
            case MsgOutType.Text:
            {
                var m = new TextMessage
                {
                    Text     = msg.Text,
                    Receiver = s.InternalChatId
                };
                await _cli.SendTextMessageAsync(m);

                break;
            }

            case MsgOutType.Keyboard:
            {
                var keyboardMsg = new KeyboardMessage
                {
                    Text          = msg.Text,
                    Receiver      = s.InternalChatId,
                    Keyboard      = GetViberKeyboard(msg.Keyboard.Buttons.ToArray()),
                    MinApiVersion = 3
                };
                await _cli.SendKeyboardMessageAsync(keyboardMsg);

                break;
            }

            case MsgOutType.Photo:
                break;

            case MsgOutType.Wait:
            {
                var m = new TextMessage
                {
                    Text     = $"Нагадування встановлено",
                    Receiver = s.InternalChatId
                };
                await _cli.SendTextMessageAsync(m);

                break;
            }

            default:
                break;
            }
        }
예제 #21
0
 private void TriggerFlags(Keys vkCode, Keys triggerKey, KeyboardMessage wmKeyboard, int i) // Sets flag for trigger keys.
 {
     if (vkCode == triggerKey && (wmKeyboard == keyDownSys || wmKeyboard == keyDown))
     {
         flagArray[i] = true;
     }
     else if (vkCode == triggerKey && (wmKeyboard == keyUp || wmKeyboard == keyUpSys))
     {
         flagArray[i] = false;
     }
 }
예제 #22
0
        public override void TriggerKeyboardInput(KeyboardMessage e)
        {
            if (e.EventType == KeyboardEventType.KeyUp)
            {
                return;
            }

            HotkeyDefinition.Keys.Clear();
            HotkeyDefinition.Keys.AddRange(Input.KeysDown);

            Invalidate();
        }
예제 #23
0
 private int CallNextHook(int code, KeyboardMessage message, ref KeyboardState state)
 {
     if (code >= 0)
     {
         KeyboardHookedEventArgs e = new KeyboardHookedEventArgs(message, ref state);
         OnKeyboardHooked(e);
         if (e.Cancel)
         {
             return(-1);
         }
     }
     return(CallNextHookEx(IntPtr.Zero, code, message, ref state));
 }
예제 #24
0
 private void Action(Keys vkCode, KeyboardMessage wmKeyboard)
 {
     if (wmKeyboard == keyDown || wmKeyboard == keyDownSys)
     {
         long   timer     = sw.ElapsedMilliseconds;
         string character = InputUtils.GetCharsFromKeys(vkCode);
         bufferObj.AddToBuffer(character, (int)normalInputSW.ElapsedMilliseconds);
         sw.Restart();
         userLevelTimer.Stop();
         userLevelTimer.Start();
         keyCount++;
     }
 }
예제 #25
0
        public async Task <string> SendTextMessage(string receiver, string text)
        {
            var message = new KeyboardMessage
            {
                Receiver     = receiver,
                Sender       = BotUserData,
                Text         = text,
                TrackingData = ViberBotTrackingData.Empty(),
                Keyboard     = KeyboardHandler.MainMenu
            };

            return(await SendMessage(receiver, message));
        }
예제 #26
0
        internal static KeyboardHookEventArgs Create(KeyboardMessage wParam, IntPtr lParam)
        {
            switch (wParam)
            {
            case KeyboardMessage.WM_KEYDOWN:
                return(new KeyboardHookEventArgs(GetButton(lParam), true));

            case KeyboardMessage.WM_KEYUP:
                return(new KeyboardHookEventArgs(GetButton(lParam), false));

            default:
                return(null);
            }
        }
예제 #27
0
 private int CallNextHook(int code, KeyboardMessage message, ref KeyboardState state)
 {
     if (code >= 0)
     {
         state.KeyCode = KeyInterop.KeyFromVirtualKey((int)state.KeyCode);
         KeyboardHookedEventArgs e = new KeyboardHookedEventArgs(message, ref state);
         OnKeyboardHooked(e);
         if (e.Cancel)
         {
             return(-1);
         }
     }
     return(CallNextHookEx(IntPtr.Zero, code, message, ref state));
 }
예제 #28
0
        public int hookProc(int nCode, int wParam, ref GlobalKeyboardHookStruct lParam)
        {
            KeyboardMessage Msg = (KeyboardMessage)wParam;

            Keys key_presed = (Keys)lParam.vkCode;

            if (key_hook_evt != null)
            {
                if (key_hook_evt(wParam, key_presed))
                {
                    return(1);
                }
            }

            return(CallNextHookEx(hookHandle, nCode, wParam, ref lParam));
        }
예제 #29
0
        public static async Task Execute(CallbackData data)
        {
            //отправить подтверждение
            var receiver = data.Sender.Id;

            var message = new KeyboardMessage
            {
                Receiver     = receiver,
                Sender       = client.BotUserData,
                Text         = $"Укажите номер вашей квартиры.",
                TrackingData = ViberBotTrackingData.Build("AddFlatNumberAction", "СonfirmSetFlatNumberAction"),
                Keyboard     = KeyboardHandler.Cancel
            };

            await client.SendMessage(receiver, message);
        }
예제 #30
0
        public static async Task Execute(CallbackData data)
        {
            //отправить подтверждение
            var receiver = data.Sender.Id;

            var message = new KeyboardMessage
            {
                Receiver     = receiver,
                Sender       = client.BotUserData,
                Text         = $"Выберите действие из списка.",
                TrackingData = ViberBotTrackingData.Empty(),
                Keyboard     = KeyboardHandler.MainMenu
            };

            await client.SendMessage(receiver, message);
        }
        public static void Process(KeyboardMessage value, Controller controller)
        {
            // Copy a system name to the clipboard

            // {"VirutalKey":49,"ScanCode":2,"Flags":0}  1
            if (value.VirutalKey == 49 && value.Flags == 1)
            {
                var systemName = Actions.GetEdsmSystemRow(1);
                new TextCopy.Clipboard().SetText(systemName);
                log.Debug($"Selected system: {systemName}");
            }

            if (value.VirutalKey == 50 && value.Flags == 1)
            {
                var systemName = Actions.GetEdsmSystemRow(2);
                new TextCopy.Clipboard().SetText(systemName);
                log.Debug($"Selected system: {systemName}");
            }

            if (value.VirutalKey == 51 && value.Flags == 1)
            {
                var systemName = Actions.GetEdsmSystemRow(3);
                new TextCopy.Clipboard().SetText(systemName);
                log.Debug($"Selected system: {systemName}");
            }

            if (value.VirutalKey == 52 && value.Flags == 1)
            {
                var systemName = Actions.GetEdsmSystemRow(4);
                new TextCopy.Clipboard().SetText(systemName);
                log.Debug($"Selected system: {systemName}");
            }

            if (value.VirutalKey == 53 && value.Flags == 1)
            {
                var systemName = Actions.GetEdsmSystemRow(5);
                new TextCopy.Clipboard().SetText(systemName);
                log.Debug($"Selected system: {systemName}");
            }

            if (value.VirutalKey == 54 && value.Flags == 1)
            {
                var systemName = Actions.GetEdsmSystemRow(6);
                new TextCopy.Clipboard().SetText(systemName);
                log.Debug($"Selected system: {systemName}");
            }
        }
 internal IntPtr HandleKeyboardEvent(int nCode, IntPtr wParam, IntPtr lParam)
 {
     if (nCode >= 0)
     {
         KBDLLHOOKSTRUCT keyboardLLHookStruct = (KBDLLHOOKSTRUCT)(Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT)));
         this.vkCode = (Keys)keyboardLLHookStruct.vkCode;
         KeyboardMessage wmKeyboard = (KeyboardMessage)wParam;
         if ((wmKeyboard == KeyboardMessage.WM_KEYDOWN || wmKeyboard == KeyboardMessage.WM_SYSKEYDOWN))
         {
             IntPtr foregroundWindow = WindowsUtilities.GetForegroundWindow();
             uint   wndProcId;
             uint   wndProcThread = WindowsUtilities.GetWindowThreadProcessId(foregroundWindow, out wndProcId);
             if (foregroundWindow == WindowsUtilities.FindWindow("CrypticWindow", null) ||
                 Process.GetCurrentProcess().Id == wndProcId)
             {
                 System.Windows.Input.Key inputKey = InputKey;
                 if ((inputKey == Key.Left || inputKey == Key.Right) && Keyboard.Modifiers == ModifierKeys.Control)
                 {
                     IntPtr winHandle = WindowsUtilities.FindWindow("CrypticWindow", null);
                     WindowsUtilities.SetForegroundWindow(winHandle);
                 }
                 else
                 {
                     lock (lockObj)
                     {
                         try
                         {
                             foreach (HandleKeyEvent _handleKeyEvent in _handleKeyEvents)
                             {
                                 EventMethod handler = _handleKeyEvent(vkCode, inputKey);
                                 if (handler != null)
                                 {
                                     handler();
                                 }
                             }
                         }
                         catch (Exception ex)
                         {
                         }
                     }
                 }
             }
         }
     }
     return(CallNextHook(hookID, nCode, wParam, lParam));
 }
예제 #33
0
 ///<summary>新しいインスタンスを作成する。</summary>
 internal KeyboardHookedEventArgs(KeyboardMessage message, ref KeyboardState state)
 {
     this.message = message;
     this.state = state;
 }
예제 #34
0
 private int CallNextHook(int code, KeyboardMessage message, ref KeyboardState state)
 {
     if (code >= 0) {
         KeyboardHookedEventArgs e = new KeyboardHookedEventArgs(message, ref state);
         OnKeyboardHooked(e);
         if (e.Cancel) {
             return -1;
         }
     }
     return CallNextHookEx(IntPtr.Zero, code, message, ref state);
 }
예제 #35
0
 private static extern int CallNextHookEx(IntPtr hook, int code, KeyboardMessage message, ref KeyboardState state);
예제 #36
0
		public void CreateKeyboardMessageWithParameter()
		{
			keyboardMessage = new KeyboardMessage(new[] { Key.Enter });
		}
예제 #37
0
		public void CanCreateKeyboardMessageWithoutParameter()
		{
			keyboardMessage = new KeyboardMessage();
			Assert.NotNull(keyboardMessage);
		}