-
Feb 6th, 2021, 05:26 AM
#1
Thread Starter
Addicted Member
Can Add_In working with hot keys?
Hi!
I want write addin for vbe which can listen user keyboard input,
and if user Press Ctrl+K, then dll must waiting another portion of command.
This needs for commenting code. And now de-facto in most popular editors.
Code:
Ctrl+K, Ctrl+C 'commented peace of code
Code:
Ctrl+K, Ctrl+U 'uncommented code
Its works in VS, MSSQL, VSCode and etc.
Now time for VBE! )
So, question is: how possible release algorithm when after pressing Ctrl+K, DLL stil waiting next command?
Ten Years After - 01 You Give Me Loving
-
Sep 5th, 2021, 06:52 AM
#2
Thread Starter
Addicted Member
Re: Can Add_In working with hot keys?
After a long search, one highly respected member of the VB team published a variant of intercepting a key combination.
This option intercepts the combination and goes into the waiting mode for subcommands.
But the problem is that it catches the hook globally throughout the system, even if the application is not active or minimized.
Could respected members of the forum help to make edits so that the application catches the Ctrl+K combination only if it has focus? Not globally. (As if the editor's code window is active.)
I have prepared a test MDI application to understand what is happening.
That is, the error here is that the interception is triggered even if the window is minimized.
TheTrick_HotKey.zip
Ten Years After - 01 You Give Me Loving
-
Sep 9th, 2021, 06:41 AM
#3
Re: Can Add_In working with hot keys?
Hi with this function you can get the classname of active control in a windows, then you can ask when you find your key combination if the class name corresponds to the one you want to use. if GetFocusCtlClasName = "VbaWindow" then ....
Code:
Option Explicit
Private Declare Function AttachThreadInput Lib "user32.dll" (ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetFocus Lib "user32.dll" () As Long
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As Long, ByRef lpdwProcessId As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Function GetFocusCtlClasName() As String
Dim ActWinHhwnd As Long
Dim ActWinThread As Long
Dim hFocusCtl As Long
Dim sStr As String
Dim lRet As Long
ActWinHhwnd = GetForegroundWindow()
ActWinThread = GetWindowThreadProcessId(ActWinHhwnd, 0)
Call AttachThreadInput(ActWinThread, App.ThreadID, True)
hFocusCtl = GetFocus()
Call AttachThreadInput(ActWinThread, App.ThreadID, False)
sStr = String(255, 0)
lRet = GetClassName(hFocusCtl, sStr, 255)
If lRet > 0 Then GetFocusCtlClasName = Left$(sStr, lRet)
End Function
-
Sep 9th, 2021, 01:19 PM
#4
Thread Starter
Addicted Member
Re: Can Add_In working with hot keys?
LeandroA, thank you very much!
I think the problem is in the following scenario:
I am working in VScode editor, it can intercept keystrokes.
then i switch to sql management studio, ok, studio also intercepts my keyboard shortcuts.
But if i run my application then it steals all keystrokes.
Which application I would not switch to anymore, my keyboard shortcuts do not work.
How to do that when my application loses focus, then my application would keep tracking the interception?
And I could easily use shortcuts in other programs.
Only when i'm activate my own app's form then key interceptor starting for listening combination.
Ten Years After - 01 You Give Me Loving
-
Sep 9th, 2021, 05:46 PM
#5
Re: Can Add_In working with hot keys?
Originally Posted by sergeos
LeandroA, thank you very much!
I think the problem is in the following scenario:
I am working in VScode editor, it can intercept keystrokes.
then i switch to sql management studio, ok, studio also intercepts my keyboard shortcuts.
But if i run my application then it steals all keystrokes.
Which application I would not switch to anymore, my keyboard shortcuts do not work.
How to do that when my application loses focus, then my application would keep tracking the interception?
And I could easily use shortcuts in other programs.
Only when i'm activate my own app's form then key interceptor starting for listening combination.
Hello, I don't know what code is using hook, subclass, from what I understand it is hook since it says it is blocking the keys, that can be solved, but you could put your code to see what it is doing, I have no experience with vbe, but you could even use Getkeystate with a timer.
-
Sep 9th, 2021, 11:46 PM
#6
Thread Starter
Addicted Member
Re: Can Add_In working with hot keys?
Hi, LeandroA,
thanks for your responsiveness.
I also ask you to consider the application not as a AddIn, but as an standalone exe application
Ten Years After - 01 You Give Me Loving
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|