Page 1 of 2

Key press?

Posted: Tue Mar 01, 2011 6:19 am
by Livengood
how can you make it tell if shift/alt/control is pushed?
like as in {SHIFT} A for cap.?

Re: Key press?

Posted: Tue Mar 01, 2011 11:34 am
by 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...

Re: Key press?

Posted: Tue Mar 01, 2011 12:28 pm
by 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

Re: Key press?

Posted: Wed Mar 02, 2011 10:20 pm
by 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.

Re: Key press?

Posted: Thu Mar 03, 2011 12:21 am
by mandai
You can use GetAsyncKeyState to look for shift keys, if it is down/up you could change a caps state in the program.

Re: Key press?

Posted: Thu Mar 03, 2011 12:44 am
by Livengood
i dont know, it usally doesnt work for some systems..

Re: Key press?

Posted: Thu Mar 03, 2011 12:55 am
by mandai
What's the problem?

Re: Key press?

Posted: Thu Mar 03, 2011 12:59 am
by code it
I think it's like
Code: Select all
If e.Shift = True And e.keycode = keys.A Then

Re: Key press?

Posted: Fri Mar 04, 2011 1:43 am
by 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 :)

Re: Key press?

Posted: Fri Mar 04, 2011 2:34 am
by 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.