Results 1 to 3 of 3

Thread: HotKey for application 2 (Aaron Young don't go by...)

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    Minsk, Belarus
    Posts
    11

    Post

    Hi,
    I sent my question about hotkey for application and Aaron Young answered on it.
    It's fine, it works... But what i want next is the hotkey - CTRL-C.
    There is some problem with this. This Key is reserved for clipboard cut-command and when
    i assign this key for my app clipboard does not change on this press.
    But this is my goal. I want to activate my app when clipboard is changed.
    Any idea?

    Thanks in advance.
    Regards.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Once you use HotKey to assign CTRL+C to your app, it no longer acts as a shortcut for the Copy Command.
    Therefore, to use CTRL+C for your Hotkey AND the Copy Command, you would need to Implement the Copy Process within your Application.
    One way to do this would be to Temporarily Unregister your Hotkey, send the Copy Comamnd, then Re-register the HotKey, eg.

    In the Module..
    Code:
    Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
    Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long) As Long
    Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    
    Private Const WM_HOTKEY = &H312
    Public Const GWL_WNDPROC = (-4)
    Public Const MOD_ALT = &H1
    Public Const MOD_CONTROL = &H2
    
    Public lPrevWndProc As Long
    
    Function SubClassedWnd(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        If Msg = WM_HOTKEY And wParam = 1 Then
            'HotKey Pressed
            'Do What You Want Here.
            'Temporarily Unregister our HotKey
            Call UnregisterHotKey(hwnd, 1)
            'Send the Copy Command
            SendKeys "^C", 1
            'Re-Register our HotKey
            Call RegisterHotKey(hwnd, 1, MOD_CONTROL, vbKeyC)
        End If
        SubClassedWnd = CallWindowProc(lPrevWndProc, hwnd, Msg, wParam, lParam)
    End Function
    In the Form..
    Code:
    Private Sub Form_Load()
        lPrevWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf SubClassedWnd)
        Call RegisterHotKey(hwnd, 1, MOD_CONTROL, vbKeyC)
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        Call UnregisterHotKey(hwnd, 1)
        Call SetWindowLong(hwnd, GWL_WNDPROC, lPrevWndProc)
    End Sub
    Having said that, there is an easier way to be notified when the Clipboard contents has changed, ie, by using the SetClipboardViewer API and adding your Form to the Notification Chain, eg.

    In a Module..
    Code:
    Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Public Declare Function SetClipboardViewer Lib "user32" (ByVal hwnd As Long) As Long
    
    Public Const GWL_WNDPROC = (-4)
    Private Const WM_DRAWCLIPBOARD = &H308
    
    Public lPrevWnd As Long
    
    Public Function SubClassedWindow(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        Static iCount As Integer
        If Msg = WM_DRAWCLIPBOARD Then
            'Clipboard Contents Changed!!
            iCount = iCount + 1
            Form1.Caption = "Clipboard Has Changed " & iCount & " Times."
        End If
        SubClassedWindow = CallWindowProc(lPrevWnd, hwnd, Msg, wParam, lParam)
    End Function
    In the Form..
    Code:
    Private Sub Form_Load()
        'Add this Form to the Clipboard Viewer Chain
        Call SetClipboardViewer(hwnd)
        'Subclass this Form
        lPrevWnd = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf SubClassedWindow)
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        'Stop Subclassing this Form.
        Call SetWindowLong(hwnd, GWL_WNDPROC, lPrevWnd)
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    Minsk, Belarus
    Posts
    11

    Post

    Aaron, thanks a lot. But you know i can't do what i want with first way.
    The second one looks more great and it works!... One again thanks...
    Regards.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width