Example #1
0
 private unsafe void OnUiControlGotFocus()
 {
     lock (KeyboardInputEvents)
     {
         int nb;
         // Get the state for all keys on the keyboard.
         byte *p = (byte *)SDL.SDL_GetKeyboardState(out nb);
         for (int i = 0; i < nb; i++)
         {
             // Check if key of scancode `i' is pressed.
             if (p[i] != 0)
             {
                 SDL.SDL_Keycode keyCode = SDL.SDL_GetKeyFromScancode((SDL.SDL_Scancode)i);
                 Keys            key;
                 if (MapKeys.TryGetValue(keyCode, out key) && key != Keys.None)
                 {
                     KeyboardInputEvents.Add(new KeyboardInputEvent
                     {
                         Key        = key,
                         Type       = InputEventType.Down,
                         OutOfFocus = true
                     });
                 }
             }
         }
     }
 }
Example #2
0
 private void OnKeyEvent(SDL.SDL_KeyboardEvent e, bool isKeyUp)
 {
     lock (KeyboardInputEvents)
     {
         Keys key;
         if (MapKeys.TryGetValue(e.keysym.sym, out key) && key != Keys.None)
         {
             var type = isKeyUp ? InputEventType.Up : InputEventType.Down;
             KeyboardInputEvents.Add(new KeyboardInputEvent {
                 Key = key, Type = type
             });
         }
     }
 }
Example #3
0
        /// <summary>
        /// 生成密钥对,正式使用时只需要调用一次,生成的密钥对需要保存,每次生成都不一样
        /// </summary>
        public static MapKeys CreateKey()
        {
            MapKeys mapkeys = new MapKeys();
            //生成密钥对
            RsaKeyPairGenerator        rsaKeyPairGenerator        = new RsaKeyPairGenerator();
            RsaKeyGenerationParameters rsaKeyGenerationParameters = new RsaKeyGenerationParameters(BigInteger.ValueOf(3), new Org.BouncyCastle.Security.SecureRandom(), 1024, 25);

            rsaKeyPairGenerator.Init(rsaKeyGenerationParameters); //初始化参数
            AsymmetricCipherKeyPair keyPair    = rsaKeyPairGenerator.GenerateKeyPair();
            AsymmetricKeyParameter  publicKey  = keyPair.Public;  //公钥
            AsymmetricKeyParameter  privateKey = keyPair.Private; //私钥

            SubjectPublicKeyInfo subjectPublicKeyInfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(publicKey);
            PrivateKeyInfo       privateKeyInfo       = PrivateKeyInfoFactory.CreatePrivateKeyInfo(privateKey);

            //生成byte密钥数据
            Asn1Object asn1ObjectPublic = subjectPublicKeyInfo.ToAsn1Object();

            byte[]     publicInfoByte    = asn1ObjectPublic.GetEncoded();
            Asn1Object asn1ObjectPrivate = privateKeyInfo.ToAsn1Object();

            byte[] privateInfoByte = asn1ObjectPrivate.GetEncoded();

            //16进制密钥对
            string HexPublicKey  = StringHelper.ByteToHex(publicInfoByte);
            string HexPrivateKey = StringHelper.ByteToHex(privateInfoByte);

            mapkeys.HexPublicKey  = HexPublicKey;
            mapkeys.HexPrivateKey = HexPrivateKey;

            //Base64密钥对
            string Base64PublicKey  = StringHelper.HexToBase64String(HexPublicKey);
            string Base64PrivateKey = StringHelper.HexToBase64String(HexPrivateKey);

            mapkeys.Base64PublicKey  = Base64PublicKey;
            mapkeys.Base64PrivateKey = Base64PrivateKey;

            //Xml密钥对
            mapkeys.XmlPublicKey  = RSAPublicKeyJava2DotNet(Base64PublicKey);
            mapkeys.XmlPrivateKey = RSAPrivateKeyJava2DotNet(Base64PrivateKey);

            return(mapkeys);
        }