?
Solved

VB5: Making a hotkey to activate a function

Posted on 2000-02-25
4
Medium Priority
?
242 Views
Last Modified: 2010-05-02
I need code that will tell windows that when a specific key, or combo, such as F12 for example, is pushed, that it should execute code from my program running in the background.  I can do this is my app has focus without problem...but I need it to work when it doesn't have focus and is running in the background minimized, or in the system tray.

And also is there a way to pull the names of all the active programs running under windows?
0
Comment
Question by:ChrisK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 2

Author Comment

by:ChrisK
ID: 2560468
By "names" I mean the title in the application menu bar for use with the AppActivate command.
0
 
LVL 14

Accepted Solution

by:
mcrider earned 400 total points
ID: 2560512
To monitor keys, you can try the GetKeyState API... Here is the documentation on the API: http://msdn.microsoft.com/library/psdk/winui/keybinpt_4z51.htm 


As for your second question, this article shows how to to pull the names of all the active programs running under windows.

VB3 How to Get Windows Master List (Task List)
http://support.microsoft.com/support/kb/articles/Q78/0/01.ASP?LNG=ENG&SA=MSDN&FR=1 

It's a 16-bit example, but here are the 32-bit api calls used in the program:

Declare Function GetWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long


You can also get the pathname of the programs executing...
HOWTO: List Running Processes
http://support.microsoft.com/support/kb/articles/Q187/9/13.ASP?LNG=ENG&SA=MSDN&FR=1 

0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2560951
To register a hot key in Windows, instead of using GetKeyState (takes CPU-power)..

Private Const WM_SETHOTKEY = &H32
 Private Declare Function SendMessageByLong Lib "user32" Alias "SendMessageA"
 (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As
 Long) As Long

 Public Enum echkModifierKeys
     HOTKEYF_SHIFT = &H1
     HOTKEYF_CONTROL = &H2
     HOTKEYF_ALT = &H4
     HOTKEYF_EXT = &H8
     HOTKEYF_SHIFTCONTROL = &H3
     HOTKEYF_ALTSHIFT = &H5
     HOTKEYF_CONTROLALT = &H6
     HOTKEYF_CONTROLALTSHIFT = &H7
 End Enum

 Public Function SetHotKey( _
         ByVal hWnd As Long, _
         ByVal eKeyCode As VBRUN.KeyCodeConstants, _
         ByVal eModifier As echkModifierKeys _
     ) As Boolean
 Dim iR As Long
 Dim lKey As Long
     ' wParam is a word with the LoByte set to
     ' the key code and the HiByte set to the modifier:
     lKey = (eKeyCode And &HFF&) Or ((eModifier And &HFF&) * &H100&)
     iR = SendMessageByLong(hWnd, WM_SETHOTKEY, lKey, 0)
     Select Case iR
     Case 2
         Err.Raise 20001, App.EXEName & ".SetHotKey", "Hot key previously
 assigned"
     Case 1
         ' success
         SetHotKey = True
     Case 0
         Err.Raise 20002, App.EXEName & ".SetHotKey", "Invalid window for Hot
 key"
     Case -1
         Err.Raise 20003, App.EXEName & ".SetHotKey", "Invalid Hot key"
     Case Else
         Err.Raise 20004, App.EXEName & ".SetHotKey", "Failed to set Hot key"
     End Select
 End Function


(code from http://www.vbaccelerator.com/codelib/comctl/hotkey.htm)
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2561088
"VBnet Subclassing: System-Wide Keyboard Trapping with RegisterHotKey"

http://www.mvps.org/vbnet/code/subclass/registerhotkey.htm
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question