将任何用户输入重定向到单独的基础程序 [英] redirect any user input to a separate underlying program

查看:72
本文介绍了将任何用户输入重定向到单独的基础程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的处女职位,所以请放轻松!

This is my virgin post so please go easy on me !

我正在用C#编写一个程序,希望以最大化的速度运行,并且始终在最前面.该应用程序将是半透明的,因此用户仍可以看到最大化的应用程序背后发生的一切.

I am writing a program in C# which I want to run maximized and always-on-top. The app will be translucent so that a user can still see everything that's going on behind my maximized application.

我的目标是实现一个场景,使用户可以(尽管我的应用程序具有焦点)仍然可以与所有其他正在运行的程序正常交互-好像是一块彩色玻璃,它只能将所有用户输入重定向到另一个预期的应用程序,例如在给定的x,y鼠标单击覆盖物后存在的内容.

I am aiming to achieve a scenario where a user can (despite my app having focus) still interact as normal with all other running programs - as if it was a piece of coloured glass which merely redirects all user input to another intended application, eg what ever exists at a given x,y mouse click behind the overlay.

基本思想是在任务栏以外的所有内容上创建一个叠加层,以向用户在屏幕上看到的所有内容应用色调或色调.

The basic idea is to create an overlay over everything other than the task bar to apply a tint or tone to everything the user sees on screen.

请记住我是本科生,所以知识有限-因此我为什么在这里.

Please bare in mind I am an undergrad so have limited knowledge - hence why I am here.

我还考虑了一些与图形驱动程序交谈以进行这些颜色更改的方法,但是我不确定前进的方向吗?

I have also considered some methodology of talking to perhaps a graphics driver to make these colour changes but I am unsure of the way forward?

我最初的重定向用户输入的想法可行吗?还是应该沿着驱动程序和Windows颜色配置文件等路线走?

Is my initial idea of redirecting user input feasible? Or should I go down the route of drivers and windows color profiles etc?

因此,关于gammaramp的想法,我尝试了他追随他,但未达到预期的效果...

So with regard to the gammaramp idea I tried out he following but not performing as expected ...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Runtime.InteropServices;
using System.Drawing;

namespace GammaRAMP
{
public class Program
{

    [DllImport("user32.dll")]
    public static extern IntPtr GetDC(IntPtr hWnd);

    [DllImport("gdi32.dll")]
    public static extern bool SetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);



    [DllImport("gdi32.dll")]
    public static extern int GetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);


    [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
    public struct RAMP
    {
        [ MarshalAs(UnmanagedType.ByValArray, SizeConst=256)] 
        public UInt16[] Red;
        [ MarshalAs(UnmanagedType.ByValArray, SizeConst=256)] 
        public UInt16[] Green;
        [ MarshalAs(UnmanagedType.ByValArray, SizeConst=256)] 
        public UInt16[] Blue;
    }

    public static void SetGamma(int gamma)
    {
        if (gamma <= 256 && gamma >= 1)
        {
            RAMP ramp = new RAMP();
            ramp.Red = new ushort[256];
            ramp.Green = new ushort[256];
            ramp.Blue = new ushort[256];

            for( int i=1; i<256; i++ )
            {
                int iArrayValue = i * (gamma + 128);

                if (iArrayValue > 65535) // I assume this is a max value.
                    iArrayValue = 65535;

                // So here I purposfully set red to max all the time expecting 
                // a lot of extra red but hardly any change occurs?

                //ramp.Red[i] = 65535; 

                // However if I do this:
                ramp.Red[i] = (ushort)iArrayValue;
                // I get VERY noticable changes?


                ramp.Blue[i] = ramp.Green[i] = (ushort)iArrayValue;
            }
            SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp);

        }
     }

    public static void Main(string[] args)
    {
        string ent = "";
        int g=0;

        // A RAMP struct to store initial values.
        RAMP r = new RAMP();
        // Store initial values.
       GetDeviceGammaRamp(GetDC(IntPtr.Zero),ref r);

        while (ent != "EXIT")
        {

            Console.WriteLine("Enter new Gamma (or 'EXIT' to quit):");
            ent = Console.ReadLine();
            try
            {
            g=int.Parse(ent);
            SetGamma(g);
            }
            catch
            {
            //Here only to catch errors where input is not a number (EXIT, for example, is a string)        
            }
        }

        // Reset any RAMP changes.
        SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref r);
        Console.ReadLine();
    }
}
}

期待您的回复,并非常感谢您的宝贵时间!

Looking forward to responses and thanks very much for your time!

好,所以我研究了上面的代码,发现如果您通过传递给public static void SetGamma(int gamma)的伽玛值的因子来更改给定的红色/绿色/蓝色渐变成员,并设置值,则您不想更改为iArrayValue = i * 128;您将获得所需的效果.现在剩下要做的就是将特定的rgb标量映射到滑块控件或一个colordialog.感谢大家的回应!

Ok so I played around with the above code and found that if you change a given red / green / blue ramp member by a factor of the gamma value passed in to public static void SetGamma(int gamma) and set values you do not want to change as iArrayValue = i * 128; you get the desired effect. All that remains to be done now is map specific rgb scalars to slider controls or maybe a colordialog. Thanks to everyone for your responses!

推荐答案

我不确定您是否要使用WinForms或WPF进行此操作.使用WPF,您可以执行以下操作:

I am not sure if you are wanting to do this with WinForms or WPF. With WPF you can do something like the following:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" Background="Transparent"
    AllowsTransparency="True" WindowStyle="None" Topmost="True" WindowState="Maximized">
</Window>

这将为您提供一个完全透明的窗口,所有单击等都将转到基础屏幕.然后,您可以将控件放在窗口上,它们将被看到并响应单击.然后,例如,如果您希望这些控件部分透明,则可以使用Opacity ="0.2".

This will give you a completely transparent window, and all clicks etc will go to the underlying screen. You can then put controls on the window, and they will be seen and respond to clicks. Then you could, for example, have Opacity="0.2" if you want those controls to be partly transparent.

此处中查找WinForms解决方案.

Look here for a WinForms solution.

要使屏幕上的色彩始终保持在顶部并且没有鼠标或键盘效果,请使用...

To just have a colored tint over the screen that always stays on top and has no mouse or keyboard effect, use...

this.TopMost = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
this.Opacity = 0.5;
int initialStyle = GetWindowLong(this.Handle, -20);
SetWindowLong(this.Handle, -20, initialStyle | 0x20);

这篇关于将任何用户输入重定向到单独的基础程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆