public bool IsClientAllowedToSendKey(Keys pKey, HiveCommunicationServerClient pClient) { if (this.AllowInput == true) { if (pClient.AllowInput == true) { // Check if key is allowed in client.AllowedKeys list Keys foundKey = Keys.None; if ((foundKey = pClient.AllowedKeys.Find(pK => pK == pKey)) != Keys.None) { if (pClient.MinimumTimeCountdown == 0) { if (this.Window.Title != "nowindowselectedinputhive" && !String.IsNullOrWhiteSpace(this.Window.Title)) { return(true); } InputHiveServerForm.LoggingQueue.Enqueue(String.Format( "{0} A key was sent from {1} but no window was set.", DateTime.Now, pClient)); } else { InputHiveServerForm.LoggingQueue.Enqueue(String.Format( "{0} Key {1} was sent from {2} but client is not allowed to send yet.", DateTime.Now, pKey, pClient)); pClient.SendMessage("sendnotallowedcooldown"); } } else { InputHiveServerForm.LoggingQueue.Enqueue(String.Format( "{0} Key {1} was sent from {2} but client is not allowed to send this key.", DateTime.Now, pKey, pClient)); pClient.SendMessage("sendnotallowedkey"); } } else { InputHiveServerForm.LoggingQueue.Enqueue(String.Format( "{0} Key {1} was sent from {2} but client is not allowed to send.", DateTime.Now, pKey, pClient)); pClient.SendMessage("sendnotallowed"); } } else { InputHiveServerForm.LoggingQueue.Enqueue(String.Format( "{0} Key {1} was sent from {2} but server is not receiving keys.", DateTime.Now, pKey, pClient)); pClient.SendMessage("nosend"); } return(false); }
/// <summary> /// Updates the allowed keys list to all clients for clientside keys checking /// </summary> /// <param name="pClient"></param> /// <param name="pKeys">List of Keys.ToString()</param> public void UpdateKeyListToClient(HiveCommunicationServerClient pClient, Keys[] pKeys) { pClient.AllowedKeys.Clear(); StringBuilder lvKeyBuilder = new StringBuilder(); foreach (Keys lvKey in pKeys) { pClient.AllowedKeys.Add(lvKey); lvKeyBuilder.Append(lvKey + ","); } pClient.ClientInformation.SendMessage(new ScsTextMessage(String.Format("keylist: {0}", lvKeyBuilder))); InputHiveServerForm.LoggingQueue.Enqueue(String.Format("{0} Updated keylist for {1}", DateTime.Now, pClient)); }
private void lbxClients_SelectedIndexChanged(object sender, EventArgs e) { this.lbxAllowedKeys.Items.Clear(); if (this.lbxClients.SelectedItem != null) { this._selectedClient = this._hiveServerSystem.Server.FindClientByString(this.lbxClients.SelectedItem.ToString()); this.UpdateUiSelectedClient(); } else { this._selectedClient = null; this.gbxViewClient.Enabled = false; } }
/// <summary> /// Sends keys to a window /// </summary> /// <param name="pKey">Keys.ToString()</param> /// <param name="pClient"></param> public void SendKey(Keys pKey, HiveCommunicationServerClient pClient) { if (this.IsClientAllowedToSendKey(pKey, pClient)) { InputHiveServerForm.LoggingQueue.Enqueue(String.Format("{0} Send key {1} from {2}", DateTime.Now, pKey, pClient)); // setting active might clear selected element? string lvTitle = NativeWin32.GetActiveProcessWindow().Title; if (lvTitle != this.Window.Title) { NativeWin32.SetForegroundWindow(this.Window.HWnd.ToInt32()); } //IntPtr child = NativeWin32.FindWindowEx(Window.hWnd, new IntPtr(0), "Edit", null); SendKeys.SendWait(this.ConvertKeyToString(pKey)); pClient.ResetCountdown(); } }