Exemplo n.º 1
0
        void ttclient_OnUserDesktopInput(int nSrcUserID, DesktopInput desktopinput)
        {
            DesktopInput[] inputs = new DesktopInput[] { desktopinput }, trans_inputs = null;
            //assumes desktop input is received in TTKEYCODE format
            WindowsHelper.DesktopInputKeyTranslate(TTKeyTranslate.TTKEY_TTKEYCODE_TO_WINKEYCODE,
                                       inputs, out trans_inputs);
            WindowsHelper.DesktopInputExecute(trans_inputs);

            //create new (or find existing) list of desktop inputs from user
            Dictionary<uint, DesktopInput> pastinputs;
            if (!desktopinputs.TryGetValue(nSrcUserID, out pastinputs))
            {
                pastinputs = new Dictionary<uint, DesktopInput>();
                desktopinputs.Add(nSrcUserID, pastinputs);
            }

            //only store key-down events and remove previous key-down events if 
            //the keys have been released
            foreach (DesktopInput input in trans_inputs)
            {
                if (input.uKeyState == DesktopKeyState.DESKTOPKEYSTATE_DOWN)
                    pastinputs.Add(input.uKeyCode, input);
                else if (input.uKeyState == DesktopKeyState.DESKTOPKEYSTATE_UP)
                    pastinputs.Remove(input.uKeyCode);
            }

            //if no keys are held by user then remove the user
            if (pastinputs.Count == 0)
                desktopinputs.Remove(nSrcUserID);
        }
Exemplo n.º 2
0
        //release keys which have been held down by user
        void closeUserDesktopInput(int nUserID)
        {
            Dictionary<uint, DesktopInput> pastinputs;
            if (!desktopinputs.TryGetValue(nUserID, out pastinputs))
                return;

            DesktopInput[] inputs = new DesktopInput[pastinputs.Count];
            int i=0;
            foreach (KeyValuePair<uint, DesktopInput> pair in pastinputs)
            {
                //invert key-down event so it's now a key up event
                //(and all keys are release by the user)
                DesktopInput input = pair.Value;
                input.uKeyState = DesktopKeyState.DESKTOPKEYSTATE_UP;
                inputs[i++] = input;
            }
            WindowsHelper.DesktopInputExecute(inputs);
        }
Exemplo n.º 3
0
 /**
  * @brief Translate platform key-code to and from TeamTalk's
  * intermediate format.
  *
  * Section @ref keytranslate has a table which shows how the keys on a US
  * 104-keyboard are translated to TeamTalk's intermediate format.
  *
  * Section @ref transdesktopinput explains how to transmit key-codes.
  *
  * @param nTranslate The key-code format to translate to and from.
  * @param lpDesktopInputs An array of #BearWare.DesktopInput structs to translate.
  * @param lpTranslatedDesktopInputs A pre-allocated array of #BearWare.DesktopInput
  * struct to hold the translated desktop input.
  * @return The number of translated #BearWare.DesktopInput stucts. If value
  * is different from @c nDesktopInputCount then some @c uKeyCode
  * values could not be translated and have been assigned the value
  * #BearWare.DesktopInputConstants.DESKTOPINPUT_KEYCODE_IGNORE.
  * @see TeamTalk.SendDesktopInput()
  * @see WindowsHelper.Execute() */
 public static int DesktopInputKeyTranslate(TTKeyTranslate nTranslate,
     DesktopInput[] lpDesktopInputs,
     out DesktopInput[] lpTranslatedDesktopInputs)
 {
     lpTranslatedDesktopInputs = new DesktopInput[lpDesktopInputs.Length];
     return TTDLL.TT_DesktopInput_KeyTranslate(nTranslate, lpDesktopInputs,
                                             lpTranslatedDesktopInputs,
                                             lpDesktopInputs.Length);
 }
Exemplo n.º 4
0
 /**
  * @brief Execute desktop (mouse or keyboard) input.
  *
  * When executed either a key-press, key-release or mouse move
  * will take place on the computer running the client
  * instance. Remember to calculate the offsets for the mouse
  * cursor prior to this call. The mouse position will be relative
  * to the screen resolution.
  *
  * The content of the #BearWare.DesktopInput struct must been translated to
  * the platform's key-code format prior to this
  * call. I.e. uKeyCode must be a either a Windows scan-code, Mac
  * OS X Carbon key-code or one of the mouse buttons:
  * #BearWare.DesktopInputConstants.DESKTOPINPUT_KEYCODE_LMOUSEBTN,
  * #BearWare.DesktopInputConstants.DESKTOPINPUT_KEYCODE_RMOUSEBTN,
  * #BearWare.DesktopInputConstants.DESKTOPINPUT_KEYCODE_MMOUSEBTN.
  *
  * @param lpDesktopInputs The mouse or keyboard inputs.
  * @return The number of mouse and keyboard events inserted.
  * @see WindowsHelper.KeyTranslate() */
 public static int DesktopInputExecute(DesktopInput[] lpDesktopInputs)
 {
     return TTDLL.TT_DesktopInput_Execute(lpDesktopInputs, lpDesktopInputs.Length);
 }
Exemplo n.º 5
0
 /**
  * @brief Send a mouse or keyboard event to a shared desktop window.
  *
  * If a user is sharing a desktop window it's possible for a
  * remote user to take control of mouse and keyboard input on the
  * remote computer. Read section @ref txdesktopinput on how to
  * transmit desktop input to a shared window.
  *
  * When the remote user receives the issued #BearWare.DesktopInput the
  * event #BearWare.TeamTalk.OnUserDesktopInput is posted to the client
  * instance sharing the desktop window.
  *
  * User rights required:
  * - ::USERRIGHT_TRANSMIT_DESKTOPINPUT
  *
  * @param nUserID The user's ID who owns the shared desktop window
  * and should receive desktop input.
  * @param lpDesktopInputs An array of #BearWare.DesktopInput structs which
  * should be transmitted to the user. Internally in the client
  * instance each user ID has an internal queue which can contain a
  * maximum of 100 #BearWare.DesktopInput structs.
  * @return FALSE If user doesn't exist or if desktop input queue is full or
  * if @c nUserID doesn't subscribe to desktop input. */
 public bool SendDesktopInput(int nUserID,
     DesktopInput[] lpDesktopInputs)
 {
     return TTDLL.TT_SendDesktopInput(m_ttInst, nUserID, lpDesktopInputs, lpDesktopInputs.Length);
 }
Exemplo n.º 6
0
 DesktopInput[] ToTTKey(DesktopInput input)
 {
     DesktopInput[] inputs = new DesktopInput[1];
     inputs[0] = input;
     DesktopInput[] translated;
     WindowsHelper.DesktopInputKeyTranslate(TTKeyTranslate.TTKEY_WINKEYCODE_TO_TTKEYCODE,
                                inputs, out translated);
     return translated;
 }
Exemplo n.º 7
0
        public void TestDesktopInput()
        {
            const string USERNAME = "******", PASSWORD = "******"; string NICKNAME = "TeamTalk.NET - " + GetCurrentMethod();
            const UserRight USERRIGHTS = UserRight.USERRIGHT_TRANSMIT_DESKTOP | UserRight.USERRIGHT_TRANSMIT_DESKTOPINPUT | UserRight.USERRIGHT_MULTI_LOGIN;
            MakeUserAccount(GetCurrentMethod(), USERNAME, PASSWORD, USERRIGHTS);
            TeamTalk ttclient = NewClientInstance();

            InitSound(ttclient);
            Connect(ttclient);
            Login(ttclient, NICKNAME, USERNAME, PASSWORD);
            JoinRoot(ttclient);

            TeamTalk ttclient2 = NewClientInstance();
            InitSound(ttclient2);
            Connect(ttclient2);
            Login(ttclient2, NICKNAME, USERNAME, PASSWORD);
            JoinRoot(ttclient2);

            TTMessage msg = new TTMessage();
            IntPtr hWnd = WindowsHelper.GetDesktopActiveHWND();
            int tx = ttclient.SendDesktopWindowFromHWND(hWnd, BitmapFormat.BMP_RGB24, DesktopProtocol.DESKTOPPROTOCOL_ZLIB_1);
            Assert.IsTrue(tx > 0);

            Assert.IsTrue(WaitForEvent(ttclient, ClientEvent.CLIENTEVENT_DESKTOPWINDOW_TRANSFER, 20000, ref msg));

            Assert.IsTrue(WaitForEvent(ttclient2, ClientEvent.CLIENTEVENT_USER_DESKTOPWINDOW, 20000, ref msg), "receive desktop window");

            Assert.AreEqual(msg.nSource, ttclient.GetMyUserID(), "desktop window from same source");

            ushort POSX = 45, POSY = 56;
            Assert.IsTrue(ttclient.SendDesktopCursorPosition(POSX, POSY), "send pos");

            Assert.IsTrue(WaitForEvent(ttclient2, ClientEvent.CLIENTEVENT_USER_DESKTOPCURSOR, 2000, ref msg), "receive desktop cursor");

            Assert.AreEqual(ttclient.GetMyUserID(), msg.nSource, "pos from origin");
            DesktopInput dskinput = (DesktopInput)msg.DataToObject();
            Assert.AreEqual(POSX, dskinput.uMousePosX);
            Assert.AreEqual(POSY, dskinput.uMousePosY);

            int cmdid = ttclient.DoSubscribe(ttclient2.GetMyUserID(), Subscription.SUBSCRIBE_DESKTOPINPUT);
            Assert.IsTrue(WaitCmdComplete(ttclient, cmdid, 2000), "wait sub");

            DesktopInput[] inputs = new DesktopInput[1];
            inputs[0] = new DesktopInput();
            inputs[0].uMousePosX = POSX;
            inputs[0].uMousePosY = POSY;
            inputs[0].uKeyCode = DesktopInputConstants.DESKTOPINPUT_KEYCODE_IGNORE;
            inputs[0].uKeyState = DesktopKeyState.DESKTOPKEYSTATE_NONE;

            DesktopInput[] trans_inputs;
            Assert.IsTrue(WindowsHelper.DesktopInputKeyTranslate(TTKeyTranslate.TTKEY_WINKEYCODE_TO_TTKEYCODE, inputs, out trans_inputs) > 0, "translate from");
            Assert.IsTrue(ttclient2.SendDesktopInput(ttclient.GetMyUserID(), trans_inputs), "send input");

            Assert.IsTrue(WaitForEvent(ttclient, ClientEvent.CLIENTEVENT_USER_DESKTOPINPUT, 2000, ref msg), "get desktop inputs");
            inputs[0] = (DesktopInput)msg.DataToObject();
            Assert.IsTrue(WindowsHelper.DesktopInputKeyTranslate(TTKeyTranslate.TTKEY_TTKEYCODE_TO_WINKEYCODE, inputs, out trans_inputs) > 0, "translate to");
            Assert.AreEqual(POSX, trans_inputs[0].uMousePosX, "same x");
            Assert.AreEqual(POSY, trans_inputs[0].uMousePosY, "same y");
            Assert.IsTrue(WindowsHelper.DesktopInputExecute(trans_inputs) > 0, "exec input");
        }