HotKey Tutorial

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
6 posts Page 1 of 1
Contributors
User avatar
bjm0008
Dedicated Member
Dedicated Member
Posts: 69
Joined: Thu Aug 13, 2009 2:35 am

HotKey Tutorial
bjm0008
Contains:
- 1 timer
- 1 button (not needed)
- 1 label (not needed)
Code: Select all
Public Class Form1
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim hotkey1 As Boolean
        Dim hotkey2 as Boolean
        hotkey2 = GetAsyncKeyState(Keys.controlkey)
        hotkey1 = GetAsyncKeyState(Keys.F12)
        If hotkey1 And hotkey2 = True Then
            Me.visible = false
        End If
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         Timer1.Enabled = True 
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Visible = False
    End Sub
End Class
Image
Last edited by bjm0008 on Sat Nov 14, 2009 12:34 am, edited 3 times in total.
Image
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Re: HotKey Tutorial
Nery
#Moved to * Board index ‹ Tutorials ‹ My Creations - Tutorials ‹ VB.NET
User avatar
Retherz123
Just Registered
Just Registered
Posts: 4
Joined: Fri Sep 17, 2010 5:40 pm

Re: HotKey Tutorial
Retherz123
cool but how do i add like 2?so its like alt 1
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: HotKey Tutorial
Axel
Retherz123 wrote:
cool but how do i add like 2?so its like alt 1
do u mean "2" cuz i don't understand you :?
2 = keys.numpad2

@ Ts ; timer requires to much cpu... i would use
Control_mousedown(ByVal e as mouseeventargs)
if e.keycode = keys.enter then
control.dosomething
end if

oh lol i quitted vb like 2 weeks ago and i already forgot everything lol
http://vagex.com/?ref=25000
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: HotKey Tutorial
mandai
I somehow doubt a keyboard event would use mouseeventargs. Anyway the reason the above code uses a timer is so the keys can be detected when a different window has focus.

Another way of doing it is with RegisterHotKey. Check out viewtopic.php?f=53&t=1138&p=11978#p11978
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: HotKey Tutorial
Axel
mandai wrote:
I somehow doubt a keyboard event would use mouseeventargs. Anyway the reason the above code uses a timer is so the keys can be detected when a different window has focus.

Another way of doing it is with RegisterHotKey. Check out viewtopic.php?f=53&t=1138&p=11978#p11978
oops yeah i meant keydown lol
http://vagex.com/?ref=25000
6 posts Page 1 of 1
Return to “Tutorials”