0

Once again I plead for assistance!

I would like to be able to register multiple hotkeys that are ran from a hidden form. The hotkey for the example program below toggles a second form when ALT+UPKEY is pressed. Right now it performs as it should, but when I uncomment the code that hides the program the hotkeys no longer work. Anyone know where I’m going wrong with this, or possibly know a work around on how to toggle a second form from a hidden program? As always, thank you in advance for your help.

Public Class Form1

Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
Public Const WM_HOTKEY As Integer = &H312

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    If m.Msg = WM_HOTKEY Then
        Form2.Show()
    End If

    MyBase.WndProc(m)

End Sub


Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    Call UnregisterHotKey(Me.Handle, 9)

End Sub


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Call RegisterHotKey(Me.Handle.ToInt32, 0, &H1, 38) '<-- registers specific hotkeys

    'Me.KeyPreview = True
    'Me.ShowInTaskbar = False
    'Me.ShowIcon = False
    'Me.Visible = False

End Sub
End Class
gregknight
  • 43
  • 9
  • What happens if you let the form be displayed and hide it with a button at some point, then redisplay it with a timer? Does the hotkey work before and after hiding the form but not while it's hidden? – jmcilhinney Jul 20 '16 at 03:55
  • Even if I add the button, once the form is hidden the hotkey no longer works. – gregknight Jul 20 '16 at 04:04
  • And the second part of my question? If you show the form again, does the hotkey start working again? – jmcilhinney Jul 20 '16 at 04:07
  • I added a button to the second form that made the first one visible again. once it was visible again the hotkeys no longer worked. – gregknight Jul 20 '16 at 04:21
  • Check whether the form's handle is different after it's redisplayed. I've never heard this to be the case but maybe the form relinquishes its handle while it's hidden and that's why messages sent to that handle don't arrive. – jmcilhinney Jul 20 '16 at 04:27
  • How would I check that? Are you asking if the code physically changes? – gregknight Jul 20 '16 at 04:29
  • You're already using the `Handle` property in code. Just look at its value before and after. If they're not the same then chances are it's changed, wouldn't you say? – jmcilhinney Jul 20 '16 at 04:32
  • As far as I can see nothing is changing. I'm more trying to figure out how to make the hotkeys work when the first(starting) form is hidden. The program starts and runs hidden, and the starting form will never be seen. – gregknight Jul 20 '16 at 04:40
  • I know what you're trying to do. I've read your question. I'm trying to gather information in order to diagnose the issue. Does the `Handle` property have the same value before hiding and after or not? – jmcilhinney Jul 20 '16 at 05:01
  • 1
    Your usage of the `Call` keyword is superfluous. – Visual Vincent Jul 20 '16 at 09:09
  • @jmcilhinney Like I said, from what I can see nothing changes. – gregknight Jul 20 '16 at 12:48
  • @jmcilhinney do you have slack? Would you be willing would take a look for me if I post the example file for you to download? – gregknight Jul 20 '16 at 14:33

0 Answers0