|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Point me in the right direction - Mouse utility...third button but have not been able to find what I'm looking for. I'm considering writing my own using VB6... What I simply want to do is: - Capture any middle click events - When a click occurs, display a list of items that the user can scroll through - Left-clicking on an item will "type" that entry into the currently selected point in the current application. - Middle-clicking the list will just close it. - Right-clicking the list will pop up a context menu to access settings, exit the app, etc. - I want to do this throughout Windows, not within a single or specific application. It would be nice if I could detect the currently active application and/or the application where the mouse was clicked over so I could present a list of items relative to that application. .... so, where would I start with this? It should be a piece of cake to write, once I figure out how to capture the mouse events from anywhere in Windows. Alternatively, does anyone know of an existing utility that can do this? Thanks! The only way I know of to capture mouse clicks that way is to use global
hooks and write a C++ DLL to handle the code that catches the click, and then forward it to your form. There maybe an ActiveX out there if you can't make a C++ DLL, but make sure that it support global hooks. While a hook procedure can reside in an EXE, a global hook requires a DLL to work correctly. If you use SetWindowsHookEx and point the hook procedure to your EXE, the function will return success, but it will monitor only the threads in your process(EXE). API functions to check: SetWindowsHookEx GetCursorPos WindowFromPoint SetForegroundWindow Messages: WM_NCMBUTTONUP WM_MBUTTONUP To display your menu, you could use the following VB6 code. It's what others are using to display a popup menu when someone clicks on a tray icon. PopupMenu mnuFile, , x, y > - Middle-clicking the list will just close it. I don't know if this is supported by VB6. You may have to use subclassing or the hook procedure. > - Right-clicking the list will pop up a context menu to access settings, It's better to use a try icon for this, or a menu item "More...", otherwise > exit the app, etc. you have to make more special coding. > - will "type" that entry into the currently selected point in the current Use Clipboard.SetText to paste the text. Note that 3rd party apps are not > application. uniform, you can't use WM_SETTEXT with some applications. WM_SETTEXT can be used to set some simple controls in 3rd party apps, like Labels and TextBoxes, but it doesn't work on grids for example, and some applications hide the details of the controls inside them so you can't easily get the hWnd for them, this includes EnumWindows and EnumChildWindows. IE for instance hides the controls that it displays on web pages. For example, you can't paste a text other than by using the clipboard or via IE Automation. Finally, global hook DLL's don't unload immediately when you uninstall the hook, sometimes the DLL stays in memory until you reboot. Also, any bugs in the hook will crash any of your applications, including the IDE, so they are not easy to develop. Keep the hook as simple as possible and use PostMessage to send information to your form(which is subclassed). Don't use SendMessage unless you are sure that your message will be processed quickly. SendMessage doesn't return to the originating app until the recipient finishes processing the message(reached End Sub/Function), including waiting for a user to click on a MsgBox. "Noozer" <dont.spam@me.here> wrote in message news:AcY1f.111295$1i.18146@pd7tw2no...Show quoteHide quote > I've been looking for a simple utility to take advantage of my scrolling > third button but have not been able to find what I'm looking for. I'm > considering writing my own using VB6... > > What I simply want to do is: > - Capture any middle click events > - When a click occurs, display a list of items that the user can scroll > through > - Left-clicking on an item will "type" that entry into the currently > selected point in the current application. > - Middle-clicking the list will just close it. > - Right-clicking the list will pop up a context menu to access settings, > exit the app, etc. > - I want to do this throughout Windows, not within a single or specific > application. It would be nice if I could detect the currently active > application and/or the application where the mouse was clicked over so I > could present a list of items relative to that application. > > ... so, where would I start with this? It should be a piece of cake to > write, once I figure out how to capture the mouse events from anywhere in > Windows. > > Alternatively, does anyone know of an existing utility that can do this? > > Thanks! > "Noozer" <dont.spam@me.here> wrote in news:AcY1f.111295$1i.18146@pd7tw2no: Show quoteHide quote > I've been looking for a simple utility to take advantage of my ok , here's a point, WH_MOUSE_LL, is a low-level mouse hook that is > scrolling third button but have not been able to find what I'm looking > for. I'm considering writing my own using VB6... > > What I simply want to do is: > - Capture any middle click events > - When a click occurs, display a list of items that the user can > scroll through > - Left-clicking on an item will "type" that entry into the currently > selected point in the current application. > - Middle-clicking the list will just close it. > - Right-clicking the list will pop up a context menu to access > settings, exit the app, etc. > - I want to do this throughout Windows, not within a single or > specific application. It would be nice if I could detect the currently > active application and/or the application where the mouse was clicked > over so I could present a list of items relative to that application. > > ... so, where would I start with this? It should be a piece of cake to > write, once I figure out how to capture the mouse events from anywhere > in Windows. > > Alternatively, does anyone know of an existing utility that can do > this? > > Thanks! > > system wide in standard VB WITHOUT and C-based DLL. the code below is good for a system-wide keyboard and/or mouse hook. call StartMouseHook to start, stopMouseHook when exiting your program. throw this code in its own module for easy reuse.... regards, DanS Code Begin ----------------------------------------------------------------- Option Explicit Public Const WH_KEYBOARD_LL = 13 Private Const WH_MOUSE_LL As Long = 14 Private Const HC_ACTION As Integer = 0 Private Const WM_MOUSEMOVE As Integer = &H200 Private Const WM_LBUTTONDOWN As Integer = &H201 Private Const WM_LBUTTONUP As Integer = &H202 Private Const WM_LBUTTONDBLCLK As Integer = &H203 Private Const WM_RBUTTONDOWN As Integer = &H204 Private Const WM_RBUTTONUP As Integer = &H205 Private Const WM_RBUTTONDBLCLK As Integer = &H206 Private Const WM_MBUTTONDOWN As Integer = &H207 Private Const WM_MBUTTONUP As Integer = &H208 Private Const WM_MBUTTONDBLCLK As Integer = &H209 Private Const WM_MOUSEWHEEL As Integer = &H20A Private Type KBDLLHOOKSTRUCT vkCode As Long ' virtual key code scanCode As Long ' scan code flags As Long ' flags time As Long ' time stamp for this message dwExtraInfo As Long ' extra info from the driver or keybd_event End Type Private Type Point x As Long y As Long End Type Private Type MSLLHOOKSTRUCT pt As Point mouseData As Integer flags As Integer time As Integer dwExtraInfo As Integer End Type Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSrc As Any, ByVal ByteLen As Long) Private kb_struct As KBDLLHOOKSTRUCT Private mouse_struct As MSLLHOOKSTRUCT Global kbd_Hook As Long Global mouse_Hook As Long Public Function startKeyboardHook() As Boolean kbd_Hook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf KeyboardProc, App.hInstance, ByVal 0&) If kbd_Hook <> 0 Then startKeyboardHook = True End If End Function Public Sub stopKeyboardHook() UnhookWindowsHookEx kbd_Hook End Sub Public Function KeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long If nCode = HC_ACTION Then CopyMemory kb_struct, ByVal lParam, LenB(kb_struct) Debug.Print kb_struct.scanCode End If KeyboardProc = CallNextHookEx(kbd_Hook, nCode, wParam, lParam) End Function Public Function startMouseHook() As Boolean mouse_Hook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf MouseProc, App.hInstance, ByVal 0&) If mouse_Hook <> 0 Then startMouseHook = True End If End Function Public Sub stopMouseHook() UnhookWindowsHookEx mouse_Hook End Sub Public Function MouseProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long If nCode = HC_ACTION Then CopyMemory mouse_struct, ByVal lParam, LenB(mouse_struct) Select Case wParam Case WM_MOUSEMOVE Case WM_LBUTTONDOWN Case WM_LBUTTONUP Case WM_LBUTTONDBLCLK Case WM_RBUTTONDOWN Case WM_RBUTTONUP Case WM_RBUTTONDBLCLK Case WM_MBUTTONDOWN Case WM_MBUTTONUP Case WM_MBUTTONDBLCLK Case WM_MOUSEWHEEL End Select End If MouseProc = CallNextHookEx(mouse_Hook, nCode, wParam, lParam) End Function --------------------------------------------------------------- Code End Could you help me implement this source code in VB.Net or give me the sample
source code from VB6 so I can try...? I appreciate it this would really help... Thanks, Jonathan titanic***@hotmai.com Show quoteHide quote "DanS" wrote: > "Noozer" <dont.spam@me.here> wrote in > news:AcY1f.111295$1i.18146@pd7tw2no: > > > I've been looking for a simple utility to take advantage of my > > scrolling third button but have not been able to find what I'm looking > > for. I'm considering writing my own using VB6... > > > > What I simply want to do is: > > - Capture any middle click events > > - When a click occurs, display a list of items that the user can > > scroll through > > - Left-clicking on an item will "type" that entry into the currently > > selected point in the current application. > > - Middle-clicking the list will just close it. > > - Right-clicking the list will pop up a context menu to access > > settings, exit the app, etc. > > - I want to do this throughout Windows, not within a single or > > specific application. It would be nice if I could detect the currently > > active application and/or the application where the mouse was clicked > > over so I could present a list of items relative to that application. > > > > ... so, where would I start with this? It should be a piece of cake to > > write, once I figure out how to capture the mouse events from anywhere > > in Windows. > > > > Alternatively, does anyone know of an existing utility that can do > > this? > > > > Thanks! > > > > > > ok , here's a point, WH_MOUSE_LL, is a low-level mouse hook that is > system wide in standard VB WITHOUT and C-based DLL. > > the code below is good for a system-wide keyboard and/or mouse hook. > > call StartMouseHook to start, stopMouseHook when exiting your program. > > throw this code in its own module for easy reuse.... > > > regards, > > DanS > > > Code Begin > ----------------------------------------------------------------- > Option Explicit > > Public Const WH_KEYBOARD_LL = 13 > Private Const WH_MOUSE_LL As Long = 14 > > Private Const HC_ACTION As Integer = 0 > > Private Const WM_MOUSEMOVE As Integer = &H200 > Private Const WM_LBUTTONDOWN As Integer = &H201 > Private Const WM_LBUTTONUP As Integer = &H202 > Private Const WM_LBUTTONDBLCLK As Integer = &H203 > Private Const WM_RBUTTONDOWN As Integer = &H204 > Private Const WM_RBUTTONUP As Integer = &H205 > Private Const WM_RBUTTONDBLCLK As Integer = &H206 > Private Const WM_MBUTTONDOWN As Integer = &H207 > Private Const WM_MBUTTONUP As Integer = &H208 > Private Const WM_MBUTTONDBLCLK As Integer = &H209 > Private Const WM_MOUSEWHEEL As Integer = &H20A > > > > Private Type KBDLLHOOKSTRUCT > vkCode As Long ' virtual key code > scanCode As Long ' scan code > flags As Long ' flags > time As Long ' time stamp for this message > dwExtraInfo As Long ' extra info from the driver or keybd_event > End Type > > Private Type Point > x As Long > y As Long > End Type > > Private Type MSLLHOOKSTRUCT > pt As Point > mouseData As Integer > flags As Integer > time As Integer > dwExtraInfo As Integer > End Type > > Public Declare Function SetWindowsHookEx Lib "user32" Alias > "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod > As Long, ByVal dwThreadId As Long) As Long > Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As > Long) As Long > > Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As > Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long > Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" > (pDest As Any, pSrc As Any, ByVal ByteLen As Long) > > Private kb_struct As KBDLLHOOKSTRUCT > Private mouse_struct As MSLLHOOKSTRUCT > > Global kbd_Hook As Long > Global mouse_Hook As Long > > Public Function startKeyboardHook() As Boolean > > kbd_Hook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf KeyboardProc, > App.hInstance, ByVal 0&) > If kbd_Hook <> 0 Then > startKeyboardHook = True > End If > > End Function > > Public Sub stopKeyboardHook() > UnhookWindowsHookEx kbd_Hook > End Sub > Public Function KeyboardProc(ByVal nCode As Long, ByVal wParam As Long, > ByVal lParam As Long) As Long > If nCode = HC_ACTION Then > CopyMemory kb_struct, ByVal lParam, LenB(kb_struct) > Debug.Print kb_struct.scanCode > End If > KeyboardProc = CallNextHookEx(kbd_Hook, nCode, wParam, lParam) > End Function > > Public Function startMouseHook() As Boolean > mouse_Hook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf MouseProc, > App.hInstance, ByVal 0&) > If mouse_Hook <> 0 Then > startMouseHook = True > End If > End Function > > Public Sub stopMouseHook() > UnhookWindowsHookEx mouse_Hook > End Sub > > Public Function MouseProc(ByVal nCode As Long, ByVal wParam As Long, > ByVal lParam As Long) As Long > If nCode = HC_ACTION Then > CopyMemory mouse_struct, ByVal lParam, LenB(mouse_struct) > Select Case wParam > Case WM_MOUSEMOVE > > Case WM_LBUTTONDOWN > > Case WM_LBUTTONUP > > Case WM_LBUTTONDBLCLK > > Case WM_RBUTTONDOWN > > Case WM_RBUTTONUP > > Case WM_RBUTTONDBLCLK > > Case WM_MBUTTONDOWN > > Case WM_MBUTTONUP > > Case WM_MBUTTONDBLCLK > > Case WM_MOUSEWHEEL > End Select > End If > MouseProc = CallNextHookEx(mouse_Hook, nCode, wParam, lParam) > End Function > --------------------------------------------------------------- > Code End >
Show quote
Hide quote
"=?Utf-8?B?Sm9uYXRoYW4=?=" <Jonat***@discussions.microsoft.com> wrote in This is a VB6 example. Simply place the above code in a module. In a news:D65AE553-56EC-4CEE-91C0-79A92F93ACDC@microsoft.com: > Could you help me implement this source code in VB.Net or give me the > sample source code from VB6 so I can try...? > > I appreciate it this would really help... > > Thanks, > Jonathan > titanic***@hotmai.com > > "DanS" wrote: > >> "Noozer" <dont.spam@me.here> wrote in >> news:AcY1f.111295$1i.18146@pd7tw2no: >> >> > I've been looking for a simple utility to take advantage of my >> > scrolling third button but have not been able to find what I'm >> > looking for. I'm considering writing my own using VB6... >> > >> > What I simply want to do is: >> > - Capture any middle click events >> > - When a click occurs, display a list of items that the user can >> > scroll through >> > - Left-clicking on an item will "type" that entry into the >> > currently selected point in the current application. >> > - Middle-clicking the list will just close it. >> > - Right-clicking the list will pop up a context menu to access >> > settings, exit the app, etc. >> > - I want to do this throughout Windows, not within a single or >> > specific application. It would be nice if I could detect the >> > currently active application and/or the application where the mouse >> > was clicked over so I could present a list of items relative to >> > that application. >> > >> > ... so, where would I start with this? It should be a piece of cake >> > to write, once I figure out how to capture the mouse events from >> > anywhere in Windows. >> > >> > Alternatively, does anyone know of an existing utility that can do >> > this? >> > >> > Thanks! >> > >> > >> >> ok , here's a point, WH_MOUSE_LL, is a low-level mouse hook that is >> system wide in standard VB WITHOUT and C-based DLL. >> >> the code below is good for a system-wide keyboard and/or mouse hook. >> >> call StartMouseHook to start, stopMouseHook when exiting your >> program. >> >> throw this code in its own module for easy reuse.... >> >> >> regards, >> >> DanS >> >> >> Code Begin >> ----------------------------------------------------------------- >> Option Explicit >> >> Public Const WH_KEYBOARD_LL = 13 >> Private Const WH_MOUSE_LL As Long = 14 >> >> Private Const HC_ACTION As Integer = 0 >> >> Private Const WM_MOUSEMOVE As Integer = &H200 >> Private Const WM_LBUTTONDOWN As Integer = &H201 >> Private Const WM_LBUTTONUP As Integer = &H202 >> Private Const WM_LBUTTONDBLCLK As Integer = &H203 >> Private Const WM_RBUTTONDOWN As Integer = &H204 >> Private Const WM_RBUTTONUP As Integer = &H205 >> Private Const WM_RBUTTONDBLCLK As Integer = &H206 >> Private Const WM_MBUTTONDOWN As Integer = &H207 >> Private Const WM_MBUTTONUP As Integer = &H208 >> Private Const WM_MBUTTONDBLCLK As Integer = &H209 >> Private Const WM_MOUSEWHEEL As Integer = &H20A >> >> >> >> Private Type KBDLLHOOKSTRUCT >> vkCode As Long ' virtual key code >> scanCode As Long ' scan code >> flags As Long ' flags >> time As Long ' time stamp for this message >> dwExtraInfo As Long ' extra info from the driver or keybd_event >> End Type >> >> Private Type Point >> x As Long >> y As Long >> End Type >> >> Private Type MSLLHOOKSTRUCT >> pt As Point >> mouseData As Integer >> flags As Integer >> time As Integer >> dwExtraInfo As Integer >> End Type >> >> Public Declare Function SetWindowsHookEx Lib "user32" Alias >> "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal >> hmod As Long, ByVal dwThreadId As Long) As Long >> Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook >> As Long) As Long >> >> Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As >> Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As >> Long Private Declare Sub CopyMemory Lib "kernel32" Alias >> "RtlMoveMemory" (pDest As Any, pSrc As Any, ByVal ByteLen As Long) >> >> Private kb_struct As KBDLLHOOKSTRUCT >> Private mouse_struct As MSLLHOOKSTRUCT >> >> Global kbd_Hook As Long >> Global mouse_Hook As Long >> >> Public Function startKeyboardHook() As Boolean >> >> kbd_Hook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf >> KeyboardProc, >> App.hInstance, ByVal 0&) >> If kbd_Hook <> 0 Then >> startKeyboardHook = True >> End If >> >> End Function >> >> Public Sub stopKeyboardHook() >> UnhookWindowsHookEx kbd_Hook >> End Sub >> Public Function KeyboardProc(ByVal nCode As Long, ByVal wParam As >> Long, ByVal lParam As Long) As Long >> If nCode = HC_ACTION Then >> CopyMemory kb_struct, ByVal lParam, LenB(kb_struct) >> Debug.Print kb_struct.scanCode >> End If >> KeyboardProc = CallNextHookEx(kbd_Hook, nCode, wParam, lParam) >> End Function >> >> Public Function startMouseHook() As Boolean >> mouse_Hook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf MouseProc, >> App.hInstance, ByVal 0&) >> If mouse_Hook <> 0 Then >> startMouseHook = True >> End If >> End Function >> >> Public Sub stopMouseHook() >> UnhookWindowsHookEx mouse_Hook >> End Sub >> >> Public Function MouseProc(ByVal nCode As Long, ByVal wParam As Long, >> ByVal lParam As Long) As Long >> If nCode = HC_ACTION Then >> CopyMemory mouse_struct, ByVal lParam, LenB(mouse_struct) >> Select Case wParam >> Case WM_MOUSEMOVE >> >> Case WM_LBUTTONDOWN >> >> Case WM_LBUTTONUP >> >> Case WM_LBUTTONDBLCLK >> >> Case WM_RBUTTONDOWN >> >> Case WM_RBUTTONUP >> >> Case WM_RBUTTONDBLCLK >> >> Case WM_MBUTTONDOWN >> >> Case WM_MBUTTONUP >> >> Case WM_MBUTTONDBLCLK >> >> Case WM_MOUSEWHEEL >> End Select >> End If >> MouseProc = CallNextHookEx(mouse_Hook, nCode, wParam, lParam) >> End Function >> --------------------------------------------------------------- >> Code End >> form, call StartMouseHook to start it. In the MouseProc function above, each event is in the Select-Case section. You can either do processing in the above Select-Case, or you can put a Public sub in the Form and call that from the above MouseProc.
Visual Basic 6.0 Working Model
Call Sub! Fill a FlexGrid control Editing an already open word document with VB6 Convert hex string to a byte How should one form call another? Simulation! Which Form Has Invoked The Sub! vbaccelerator - compile ListView for Unicode? A Class to get the name of Enum constant at runtime |
|||||||||||||||||||||||