Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

User assigned hotkeys

Code
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Short
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
      Dim Chrctr As Integer
      For x = 1 To 255
      Chrctr = 0 : Chrctr = GetAsyncKeyState(x)
      If Chrctr = -32767 Then : RichTextBox1.Text += Chr(x) & vbNewLine : End If
      Next x
    End Sub

i guess im a hero now :D
You shouldn't need to use anything like NaMeMaN suggests from what I can tell. Just create a KeyDown event and it will detect keypresses.

Code
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
    TextBox1.Text = e.KeyData.ToString()
End Sub

The format isn't probably what you're expecting, but you can easily format that. ex:

Ctrl + Shift + F --> F, Shift, Control
a --> A
Backspace -> Back
Ctrl + Alt + B --> B, Control, Alt
(May 21, 2015 05:31 PM)iGuessSo Wrote:  You shouldn't need to use anything like NaMeMaN suggests from what I can tell.

(May 21, 2015 12:46 PM)MrRapidz Wrote:  I basically need to detect the name of the key pressed, the key's name needs to be the same name that it uses in code though (ex. 1's name in code is D1).

He wants to 'detect' the key pressed and have use of the key's code.

For x = 1 To 255
Chrctr = 0
Chrctr = GetAsyncKeyState(x)
If Chrctr = -32767 Then
RichTextBox1.Text += Chr(x) & vbNewLine
End If
Next x

X is the integer value of the character being detected.

A = 65, B = 66, C = 67, D = 68, etc...

From what he said in his post, I believe what I have given him is more than sufficient to satify the desires of the OP. My first thoughts were he was wanting to make a customizable hotkey based on the detected key, but then after reading through his post I realized he was simply asking to save the key presses so I came up with this.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by FateNov 5, 2020 12:46 PM 3 154 Nov 5, 2020 12:46 PM
Last Post: Fate
[C] by maryousMay 9, 2018 06:07 PM 19 689 May 9, 2018 06:07 PM
Last Post: 0xDEAD10CC
[C#] by neiqhtworksFeb 8, 2016 04:01 AM 1 115 Feb 8, 2016 04:01 AM
Last Post: RedWaters