Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi, i'm trying to write a program that is either minimised to the taskbar. This program will listen for certain keypresses, for example if the user presses 'P' it will trigger an event, which will save a screendump of the screen to a file on the system. (It should listen for keypresses whilst minimised - i know how to do it if the form has focus).

 

Could someone please give me a few pointers? I guess i need to do something with the WinAPI's, but how can i find out which API i need to call, and ermmm... do i call it?

 

Thanks.

 

:rolleyes:

Edited by Jay1b
Posted

You want to use the RegisterHotKey API I think though I've never used it myself.

 

The below is a VB6 example from API guide:

 

Private Const MOD_ALT = &H1
Private Const MOD_CONTROL = &H2
Private Const MOD_SHIFT = &H4
Private Const PM_REMOVE = &H1
Private Const WM_HOTKEY = &H312
Private Type POINTAPI
   x As Long
   y As Long
End Type
Private Type Msg
   hWnd As Long
   Message As Long
   wParam As Long
   lParam As Long
   time As Long
   pt As POINTAPI
End Type
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private bCancel As Boolean
Private Sub ProcessMessages()
   Dim Message As Msg
   'loop until bCancel is set to True
   Do While Not bCancel
       'wait for a message
       WaitMessage
       'check if it's a HOTKEY-message
       If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
           'minimize the form
           WindowState = vbMinimized
       End If
       'let the operating system process other events
       DoEvents
   Loop
End Sub
Private Sub Form_Load()
   'KPD-Team 2000
   'URL: [url]http://www.allapi.net/[/url]
   'E-Mail: [email]KPDTeam@Allapi.net[/email]
   Dim ret As Long
   bCancel = False
   'register the Ctrl-F hotkey
   ret = RegisterHotKey(Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyF)
   'show some information
   Me.AutoRedraw = True
   Me.Print "Press CTRL-F to minimize this form"
   'show the form and
   Show
   'process the Hotkey messages
   ProcessMessages
End Sub
Private Sub Form_Unload(Cancel As Integer)
   bCancel = True
   'unregister hotkey
   Call UnregisterHotKey(Me.hWnd, &HBFFF&)
End Sub

 

Clearly you will need to modify it to work with .net.

 

:)

Please check the Knowledge Base before you post.

"Computers are useless. They can only give you answers." - Pablo Picasso

The Code Net

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...