473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Can a key- say F3 be bound to a string with C#?

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 ***
Nov 17 '05 #1
11 1873
"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

}
Nov 17 '05 #2
"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.
Nov 17 '05 #3
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

}

Nov 17 '05 #4
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OA*************@TK2MSFTNGP09.phx.gbl...
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).


Of course you're right. I took the OP to be more of a "how do I respond to
the function keys?" question rather than "how can I hard-code my passwords
into my apps?" type of question...

I've done similar things myself, though I tend to wrap such functionality up
in the #if(DEBUG)...#endif syntax to allow me to do stuff in debug mode that
my users can't do in release mode...
Nov 17 '05 #5
"Paul E Collins" <fi******************@CL4.org> wrote in message
news:dc**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
Yes, but you'll almost certainly need to use some Window API calls.


???

All he wants to do is click on a textbox, hit F3 and have some hard-coded
text appear in that textbox...

In the KeyDown or KeyPress event of the TextBox:

if(e.KeyCode == Keys.F3)
{
textBox1.Text = "Hello"; // or whatever you've called the TextBox
}
Nov 17 '05 #6
Mark Rae <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote:
"Paul E Collins" <fi******************@CL4.org> wrote in message
news:dc**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
Yes, but you'll almost certainly need to use some Window API calls.


???

All he wants to do is click on a textbox, hit F3 and have some hard-coded
text appear in that textbox...

In the KeyDown or KeyPress event of the TextBox:

if(e.KeyCode == Keys.F3)
{
textBox1.Text = "Hello"; // or whatever you've called the TextBox
}


It's not clear from the original post whether he wants to do it in
*his* application or in others (eg IE) though. I *suspect* he's talking
about the latter - wanting to write a background program which binds to
F3 whatever app he's using. That's clearly a lot harder - *if* it's
what is meant.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #7
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
It's not clear from the original post whether he wants to do it in
*his* application or in others (eg IE) though. I *suspect* he's talking
about the latter - wanting to write a background program which binds to
F3 whatever app he's using. That's clearly a lot harder - *if* it's
what is meant.
That's not how I read it at all...
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!


To me, that says he's going through the testing phase and is bored of having
to type in a low-security password many times, and is looking for a way to
click on a text box and have the password filled in by hitting F3 rather
than by constantly typing it out.
Nov 17 '05 #8
"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> 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 [...]


To me, that says he's going through the testing phase and
is bored of having to type in a low-security password
many times,


Type it into what? His own application, or SQL Server, or a Web site?

Frankly I felt that making a keypress produce characters in a textbox
is *so* trivial that the poster had to mean doing it in a different
window.

P.
Nov 17 '05 #9
Wow, so many replies so soon, I'll have to check in more often :-)

OK, so yes that's all I'm looking for- I'm doing web testing with IE 6,
I don't have access to the source code of the application itself. All I
want to do is to input a password into a text box in IE and I do it so
many times per hour that its terribly redundant to not have it bound
somehow.
Thanks again,

AC

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #10
... and if it is in fact so trivial, to simply bind a keypress to put
text into an IE6 field (I thought so too!) then perhaps you would be so
kind as to enlighten us as to how it is done. No offense meant, but I
think you will find it to be a less 'trivial' task once you have
acutally tried to find the solution ;-)
Thanks again,

AC

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #11
arcticool <ar*******@devdex.com> wrote:
.. and if it is in fact so trivial, to simply bind a keypress to put
text into an IE6 field (I thought so too!) then perhaps you would be so
kind as to enlighten us as to how it is done. No offense meant, but I
think you will find it to be a less 'trivial' task once you have
acutally tried to find the solution ;-)


No-one claimed that that task was trivial - it's just that your
original description wasn't clear enough to distinguish between the
task which *is* trivial (making a text box in your own application do
what you want) and the task which is very hard (making a text box in
another application do what you want).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Westcoast Sheri | last post by:
Which will be a faster lookup of an item by, "color" in the following mySQL tables: "unique key," "primary key," or just plain "key"?? CREATE TABLE myTable ( number int(11) NOT NULL default '0',...
2
by: geoff | last post by:
The table creation script(at the end of this post) works fine on 4.0.1-alpha-win, but the foreign key constraints fail on 4.0.15-win. I am starting the server with the same command for both...
6
by: Sahil Malik [MVP] | last post by:
Public Private Key Pairs - How do they work? ----------------------------------------------- I was looking at a presentation recently in which it was suggested that - User 1 Encrypts a message...
1
by: Yobbo | last post by:
Hi All I use the following script to stop users typing in anything but standard chars (eg letters, numbers, etc) into a input textbox: <!-- // 8 = backspace // 9 = tab // 46 = del // 190 =...
4
by: Thomas Mlynarczyk | last post by:
Hello, I have two arrays like this: $aSearch = array( 'A', 'B', 'C.D', 'E', 'F' ); $aSubject = array( 'A' =0, 'A.B' =1, 'X' =2, 'C.D.E' =3, 'A.B.C' => 4 ); Now I want to search $aSubject...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.