Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,257 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,200 people online right now. Registration is fast and FREE... Join Now!




reading keypresses

 
Reply to this topicStart new topic

reading keypresses

fangedleprechaun
13 Oct, 2008 - 02:25 PM
Post #1

New D.I.C Head
*

Joined: 13 Oct, 2008
Posts: 3

Hey everybody
I am starting a new project and have unfortunately run into a problem at the first hurdle, GREAT!

The code i have thus far is:

CODE
  Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        Dim word As String = ""
        If My.Computer.Keyboard.ShiftKeyDown Then
            word = e.KeyChar
            Me.Text = Me.Text & word
        Else
            word = e.KeyChar
            Me.Text = word
        End If
    End Sub


asyew can see when a key is pressed it is assigned to the forms text value. but, what i want to happen when shift is held down is that more than one letter is typed within the text value. hope that makes some kind of sense toyew.
the problem i am faced with is that when shift is held downyew can add more than one letter but any letters left in the text value from a previous type is added too rather than a new value being started.

i'm sorry if that doesnt make sense. probably be easier to test the code and see what im rambling on about.
thankyew
User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: Reading Keypresses
13 Oct, 2008 - 02:33 PM
Post #2

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,163



Thanked: 32 times
Dream Kudos: 1625
My Contributions
Yeah, i have no idea. I i know is that code will whenever a key is pressed, assign that key to the form's text value. However, if shift is down, it will append that key to the forms text value. Is that not what you want it to do? I don't get it.
User is offlineProfile CardPM
+Quote Post

fangedleprechaun
RE: Reading Keypresses
13 Oct, 2008 - 02:36 PM
Post #3

New D.I.C Head
*

Joined: 13 Oct, 2008
Posts: 3

yeah thats what i want it to do . except when shift is held down i first want it to clear the forms text .
User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: Reading Keypresses
13 Oct, 2008 - 02:39 PM
Post #4

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,163



Thanked: 32 times
Dream Kudos: 1625
My Contributions
Huh? then what's the use of having the shift thing? I don't get it. What your code will do, is if a key is pressed without shift, it will set the form's text to that key. However, you just told me if shift is pressed, you want to do the same thing? Try to give me some sort of example, maybe i'm just slow.
User is offlineProfile CardPM
+Quote Post

fangedleprechaun
RE: Reading Keypresses
13 Oct, 2008 - 02:42 PM
Post #5

New D.I.C Head
*

Joined: 13 Oct, 2008
Posts: 3

okay, if shift isn't pressed then:

pressing a will set the text to a
then
pressing b will set the text to b

if shift is pressed then:

pressing a will set the text to a
then
pressing b will set the text to ab

with me now?


User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: Reading Keypresses
13 Oct, 2008 - 03:23 PM
Post #6

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,163



Thanked: 32 times
Dream Kudos: 1625
My Contributions
Yes, but your original code will do that.
User is offlineProfile CardPM
+Quote Post

DeCompile
RE: Reading Keypresses
13 Oct, 2008 - 03:36 PM
Post #7

D.I.C Head
**

Joined: 20 Jul, 2008
Posts: 180



Thanked: 6 times
My Contributions
Interesting problem:

Try this:

If My.Computer.Keyboard.ShiftKeyDown Then
Label1.Text += e.KeyChar.ToString.ToLower
Else
Label1.Text = e.KeyChar
End If

Is this the effect that you're after?
User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: Reading Keypresses
13 Oct, 2008 - 03:37 PM
Post #8

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,163



Thanked: 32 times
Dream Kudos: 1625
My Contributions
Maybe, except it's not Label1.Text, it's Me.Text.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 04:30AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month