密钥 - 说F3可以绑定到C#的字符串吗? [英] Can a key- say F3 be bound to a string with C#?

查看:64
本文介绍了密钥 - 说F3可以绑定到C#的字符串吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个常用的密码,安全性较低,但是我的

应用程序测试的一部分,所以我想以某种方式将它绑定到F键上说F3

可能是F4的另一个。所以我可以点击字段然后点击F3到

填写PW。


如果你看到我每天要做多少次这个你会理解

我愿意为这样的事情编码!


这样可以用C#完成吗?我确实有一些基本的c#经验,可以用一点指导将它们放在一起。

谢谢,


Jeff


***通过开发人员指南 http://www.developersdex发送。 com ***

解决方案

" arcticool" < AR ******* @ devdex.com>在消息中写道

news:uF ************** @ TK2MSFTNGP10.phx.gbl ...

所以这可以用C#完成吗?




轻松自如。


在TextBox的KeyDown或KeyPress事件中,添加以下内容:


if(e.KeyCode == Keys.F3)


{


textBox1.Text =" Hello" ;; //或者你称之为TextBox的任何东西


}


" arcticool" < AR ******* @ devdex.com>写道:

我有一个常用的密码,安全性低,但是我的应用程序测试的一部分,所以我想要以某种方式将它绑定到F -key说F3
[...]所以我可以点击该字段然后点击F3来填写PW。 [...]这可以用C#来完成吗?




是的,但你几乎肯定需要使用一些Window API调用。


这是'我将如何做到这一点:


- 使用API​​函数SetWindowsHookEx创建一个键盘钩子,所以

你的应用程序即使在没有活动时也可以接收击键。

(不幸的是,这需要很多代码,因为.NET

Framework没有内置支持钩子。作为一个便宜的替代方案,你可以设置一个定时器,每次调用GetAsyncKeyState几次

秒来检查你想要的键是否被按下*对

现在*。)


- 当你得到你感兴趣的击键时,使用SendKeys(不是

an API,但是.NET Framework的一部分)将您的密码

字符发送到当前活动的窗口。


P.


当然,那时,你有e询问具有

密码的目的是什么,因为密码现在将以纯文本形式嵌入到程序集中

本身,不能少于任何人都可以看到反编译器(甚至是
ILDASM)。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Mark Rae" <毫安** @ mark-N-O-S-P-A-M-rae.co.uk>在消息中写道

news:%2 **************** @ TK2MSFTNGP14.phx.gbl ...

" arcticool" < AR ******* @ devdex.com>在消息中写道
新闻:uF ************** @ TK2MSFTNGP10.phx.gbl ...

这样就可以了使用C#?



最简单易用。

在TextBox的KeyDown或KeyPress事件中,添加以下内容:
if(e.KeyCode == Keys.F3)



textBox1.Text =" Hello" ;; //或任何你称之为TextBox

}



I have a commonly used password that is low security, but part of my
application testing so I want to just bind it somehow to an F-key say F3
and maybe another to F4. So I can click on the field and just hit F3 to
fill in the PW.

If you saw how many times a day I have to do this you would understand
my willingness to code for such a thing!

So can this be done with C#? I do have some basic c# experience and can
put it together with a little guidance.
Thanks,

Jeff

*** Sent via Developersdex http://www.developersdex.com ***

解决方案

"arcticool" <ar*******@devdex.com> wrote in message
news:uF**************@TK2MSFTNGP10.phx.gbl...

So can this be done with C#?



With the greatest of ease.

In the KeyDown or KeyPress event of the TextBox, add the following:

if(e.KeyCode == Keys.F3)

{

textBox1.Text = "Hello"; // or whatever you''ve called the TextBox

}


"arcticool" <ar*******@devdex.com> wrote:

I have a commonly used password that is low
security, but part of my application testing so I
want to just bind it somehow to an F-key say F3
[...] So I can click on the field and just hit F3 to
fill in the PW. [...] So can this be done with C#?



Yes, but you''ll almost certainly need to use some Window API calls.

Here''s how I would do this:

- Use the API function SetWindowsHookEx to create a keyboard hook, so
your application can receive keystrokes even when it is not active.
(This requires quite a lot of code, unfortunately, because the .NET
Framework has no built-in support for hooks. As a cheap alternative,
you could set up a timer that calls GetAsyncKeyState several times per
second to check whether the key you want is being pressed *right
now*.)

- When you get the keystroke you''re interested in, use SendKeys (not
an API, but part of the .NET Framework) to send your password
characters to the currently active window.

P.


Of course, at that point, you have to ask what the purpose of having a
password is, since the password is now going to be embedded in the assembly
itself, in plain text, no less, for anyone to see with a decompiler (or even
ILDASM).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...

"arcticool" <ar*******@devdex.com> wrote in message
news:uF**************@TK2MSFTNGP10.phx.gbl...

So can this be done with C#?



With the greatest of ease.

In the KeyDown or KeyPress event of the TextBox, add the following:

if(e.KeyCode == Keys.F3)

{

textBox1.Text = "Hello"; // or whatever you''ve called the TextBox

}



这篇关于密钥 - 说F3可以绑定到C#的字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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