Solved

VB5: Making a hotkey to activate a function

Posted on 2000-02-25
4
234 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
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 100 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 / DAO 3.6 / run time error: Couldn't find installable ISAM 7 94
message box in access 4 46
vb6 connector to mongodb 2 84
Help me. 3 56
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

810 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