Key press?

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
14 posts Page 1 of 2
Contributors
User avatar
Livengood
Serious Programmer
Serious Programmer
Posts: 445
Joined: Tue Feb 16, 2010 6:24 am

Key press?
Livengood
how can you make it tell if shift/alt/control is pushed?
like as in {SHIFT} A for cap.?
Image
User avatar
bisnes_niko
Serious Programmer
Serious Programmer
Posts: 409
Joined: Tue Aug 24, 2010 1:21 pm

Re: Key press?
bisnes_niko
If you don't need that as a key combination, why not to use

SendKeys.Send("A")

EDIT: I am not sure, but you could give a try for SendKeys.Send("{SHIFT}"+"{A}")
EDIT: @Mandai, my bad...
Last edited by bisnes_niko on Tue Mar 01, 2011 12:30 pm, edited 1 time in total.
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Key press?
mandai
I don't think we are trying to send keys.
You can tell if keys are being held with GetAsyncKeyState.
Code: Select all
    <DllImport("user32.dll")> Shared Function GetAsyncKeyState(ByVal vKey As Integer) As Short
    End Function

    Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
        Dim res As Short = GetAsyncKeyState(Keys.LShiftKey)
        If res = -32767 Then
            MsgBox("Left shift is down")
        End If

    End Sub
User avatar
Livengood
Serious Programmer
Serious Programmer
Posts: 445
Joined: Tue Feb 16, 2010 6:24 am

Re: Key press?
Livengood
Now i have a key hook that i am building, but i need to get it to work with the SHIFT so i can get upper case A's instead of only lower case.
Image
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Key press?
mandai
You can use GetAsyncKeyState to look for shift keys, if it is down/up you could change a caps state in the program.
User avatar
Livengood
Serious Programmer
Serious Programmer
Posts: 445
Joined: Tue Feb 16, 2010 6:24 am

Re: Key press?
Livengood
i dont know, it usally doesnt work for some systems..
Image
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Key press?
mandai
What's the problem?
User avatar
code it
VIP - Site Partner
VIP - Site Partner
Posts: 821
Joined: Sun Oct 10, 2010 3:02 pm

Re: Key press?
code it
I think it's like
Code: Select all
If e.Shift = True And e.keycode = keys.A Then
User avatar
Livengood
Serious Programmer
Serious Programmer
Posts: 445
Joined: Tue Feb 16, 2010 6:24 am

Re: Key press?
Livengood
I have having the issue with getting the shift key and all other keys besides the main letter keys...
Code: Select all
Imports System.Runtime.InteropServices
Public Class Form1
    Private WithEvents keyboard As New KeyboardHook
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Dim shift As Boolean
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        RichTextBox1.Text = TextBox1.Text
    End Sub

    Private Sub keyboard_KeyDown(ByVal Key As System.Windows.Forms.Keys) Handles keyboard.KeyDown
        
        If Key = Keys.Space Then
            TextBox1.AppendText(" ")
        End If
        If Key = Keys.Enter Then
            TextBox1.AppendText(vbNewLine)
        End If
    End Sub
End Class
theres my main class, the key hook i have got from online :)

code it wrote:
I think it's like
Code: Select all
If e.Shift = True And e.keycode = keys.A Then
this would be if its for like a component in the program, i am using a key hook..
so its built to read keys :)
Image
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Re: Key press?
Usman55
I tried this code a while ago in my browser and had to remove it later cuz it didn't work. SO if you find out, please tell me so.
Image
14 posts Page 1 of 2
Return to “Tutorial Requests”