Skip to main content

Control Hotkeys

Image Credits VNAMedia

This weekend I plan to learn coding hotkeys and sending them to Winforms, basically for fun. I was testing the Control + N hotkeys and came up with some really useful text book material. This particular code was made to test things and worked great. I was happy and posted it here to ease the work for you.

Public Const MOD_CTRL As Integer = &H2 'Control key
    Public Const WM_HOTKEY As Integer = &H312

    <DllImport("User32.dll")> _
    Public Shared Function RegisterHotKey(ByVal hwnd As IntPtr, _
                        ByVal id As Integer, ByVal fsModifiers As Integer, _
                        ByVal vk As Integer) As Integer
    End Function

    <DllImport("User32.dll")> _
    Public Shared Function UnregisterHotKey(ByVal hwnd As IntPtr, _
                        ByVal id As Integer) As Integer
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, _
                        ByVal e As System.EventArgs) Handles MyBase.Load
        RegisterHotKey(Me.Handle, 100, MOD_CTRL, Keys.N)
        'RegisterHotKey(Me.Handle, 200, MOD_CTRL, Keys.C)
    End Sub

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = WM_HOTKEY Then
            Dim id As IntPtr = m.WParam
            Select Case (id.ToString)
                Case "100"
                    MessageBox.Show("You pressed CTRL+N key combination")
                    '  Case "200"
                    'MessageBox.Show("You pressed ALT+C key combination")
            End Select
        End If
        MyBase.WndProc(m)
    End Sub

You should also check out these sites to know about more details.

http://www.xtremevbtalk.com/showthread.php?t=185548

http://social.msdn.microsoft.com/Forums/pl-PL/vblanguage/thread/3cc4da38-7846-4277-8dae-ef8fe4e66dc8

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/c1a24688-d844-4adc-9d85-416a7158c6ba/

http://www.eggheadcafe.com/searchform.aspx?search=WM_SYSKEYDOWN

http://www.kirsbo.com/2010/how-to-add-global-hotkeys-to-applications-in-vb-net/

Comments

Popular posts from this blog

Republic of India's sustained discrimination of Hindus

Republic of India has been independent for over 70 years now. Ever since 1947, and particularly since 1950 many Governments have come and gone. The Constitution of India has been amended. By over 370 times and counting. The name of the nation has also changed. From the simple 'Republic of India' it was changed to the 'Secular Sovereign Socialist Democratic Republic of India' for reasons best known to the then ruling elites. Few policies have remained unchanged or unchallenged regardless of the different Governments, political parties, emergencies and so on.

That is the systematic institutional and legal discrimination of Hindus.

Sounds surprising?

And yes, BJP fanboys - you are just as guilty if not more. Let me explain why.

There are plenty of laws, rules and regulations that this marvellous Republic of ours has given us. Learning about the laws that govern our lives require us to take a Law degree. Literally. The Constitution that we are bound to live by is somethin…

Fallen - Based on a true story (almost)

A group of young guys had gathered around a lifeless body on the road. A minivan had just hit a girl and sped off. The girl bounced on the road and rolled around once and came to a stop. The rest of the girls on the street scattered. A couple of guys came to check on the girl. A crowd gathered and collected what little valuables she had left with her.

A girl saw it all from her second floor window on Sheil road, Liverpool. Natalie was aware of the hazards of what she used to do. She knew the roads were dangerous, especially at night. But then, day or night - she was never truly safe. Her escape was only in heroin. She did not dare to build a world of her own by her own means. She tried before. It never worked out. So she had transferred the responsibility to what society calls ‘substance’. Heroin gave her a cushion, her sleep and let her keep her sanity. Or so she used to think.

Natalie was alone. Her addiction was not. It came with dependence, depression, homelessness and rejection. He…

A Good Day

I have a beautiful small house in the hills. It is about 3 km from Manali, in Himachal Pradesh. It is not much. Probably calling it a cottage is stretching it too far. I have got a couple of bedrooms, a small drawing room cum kitchen where we dine as well. There is storage and a small garage that is mostly empty. I have got another small room with just a single bed and a study built on the first floor. It is just about ten feet by ten feet but it has got a retractable ceiling and a wall made of glass with the rest of the roof being something of a balcony. This is the place where I like to spend most of my time. x

In the front, there is a garden with some flowers in the front and trees lining the boundary wall. My mother has planted a few vegetables in the back that we regularly use in the kitchen. We mostly require only rice and eggs from the market.

A typical day starts with me waking up and going for a morning stroll. I often spend my nights in the room on the roof. So the first thing…