Beispiel #1
0
 protected virtual void Validate_3_SpecialCases()
 {
     if (InterceptedMethod.IsConstructor && (HookType != MethodHookType.RunAfter))
     {
         throw new ArgumentException("Intercepted Method appears to be a constructor for a type (" + InterceptedMethod.DeclaringType.FullName + "). Only MethodHookType.RunAfter is currently supported for constructors.");
     }
     if (HookFlags.HasFlag(MethodHookFlags.CanSkipOriginal))
     {
         if (HookType != MethodHookType.RunBefore)
         {
             throw new ArgumentException("MethodHookFlags.CanSkipOriginal requires MethodHookType.RunBefore!");
         }
     }
 }
Beispiel #2
0
        public static int hook(int scanCode, int virtualCode, HookMessage message, HookFlags flags, IntPtr param)
        {
            KeyEvent keyEvent = new KeyEvent();

            keyEvent.scanCode    = scanCode;
            keyEvent.virtualCode = virtualCode;
            keyEvent.hookMessage = message;

            int nFlags = (int)flags;

            if ((nFlags & (int)HookFlags.HF_ExtendedKey) > 0)
            {
                keyEvent.extendedKey = true;
            }

            if ((nFlags & (int)HookFlags.HF_AltKeyPressed) > 0)
            {
                keyEvent.altKeyPressed = true;
            }

            if ((nFlags & (int)HookFlags.HF_InjectedKey) > 0)
            {
                keyEvent.injectedKey = true;
            }

            if ((nFlags & (int)HookFlags.HF_KeyPress) > 0)
            {
                keyEvent.keyPress = true;
            }

            if ((nFlags & (int)HookFlags.HF_SentFromLibrary) > 0)
            {
                keyEvent.sentFromLibrary = true;
            }


            form.AddEvent(keyEvent);

            return(hookReturnValue);
        }
        public static int hook(int scanCode, int virtualCode, HookMessage message, HookFlags flags, IntPtr param)
        {
            KeyEvent keyEvent = new KeyEvent();
            keyEvent.scanCode = scanCode;
            keyEvent.virtualCode = virtualCode;
            keyEvent.hookMessage = message;

            int nFlags = (int)flags;

            if ((nFlags & (int)HookFlags.HF_ExtendedKey) > 0)
            {
                keyEvent.extendedKey = true;
            }

            if ((nFlags & (int)HookFlags.HF_AltKeyPressed) > 0)
            {
                keyEvent.altKeyPressed = true;
            }

            if ((nFlags & (int)HookFlags.HF_InjectedKey) > 0)
            {
                keyEvent.injectedKey = true;
            }

            if ((nFlags & (int)HookFlags.HF_KeyPress) > 0)
            {
                keyEvent.keyPress = true;
            }

            if ((nFlags & (int)HookFlags.HF_SentFromLibrary) > 0)
            {
                keyEvent.sentFromLibrary = true;
            }

            form.AddEvent(keyEvent);

            return hookReturnValue;
        }
Beispiel #4
0
 protected virtual void Validate_5_ReturnType()
 {
     //Return value checking
     if (HookFlags.HasFlag(MethodHookFlags.CanSkipOriginal))
     {
         if (CustomMethod.ReturnType != typeof(bool))
         {
             throw new ArgumentException("Methods that can skip the original method have to return a bool, indicating the skipping state");
         }
     }
     else if ((HasResultAsFirstParameter || (HookType == MethodHookType.Replace)) && (InterceptedMethod is MethodInfo))
     {
         var expected_type = (InterceptedMethod as MethodInfo).ReturnType;
         if (expected_type != CustomMethod.ReturnType)
         {
             Validate_5_ReturnType_WrongReturnType(CustomMethod.ReturnType, expected_type, CustomMethod);
         }
     }
     else if (CustomMethod.ReturnType != typeof(void))
     {
         Validate_5_ReturnType_WrongReturnType(CustomMethod.ReturnType, typeof(void), CustomMethod);
     }
 }