Key Scan Code to launch application

GreenBug
09-08-2003, 06:32 AM
hi sorry if this is a silly question but i am new to vb, i am trying to wright an app to launch a .exe when one of the custom buttons is pressed on my dell insperon 8100 dell provide an application to do this but you can only customise 2 of the 4 buttons and id realy like to be able to customise all 4. looking at the dell program i get what i think are the button scan codes from the registory (e001 to e004) but i am unshure how to right them into an app the closist i have is this:
If GetAsyncKeyState(vbKeyQ) Then
Shell ("C:\Program Files\Microsoft Visual Studio\VB98\vb6.exe")
End If
but i am unshure how to change the key as its a non standard key i need to put the scan code in rather than a difrent vbkey

thanks for your help

passel
09-08-2003, 06:40 AM
I would try just adding code to your form_keydown routine and see if
it prints out a keycode. If not, then I don't know, but if it does, then
you can try and use that number in the GetAsyncKeyState function to
see if it will work. If it doesn't work in the GetAsyncKeyState, but did
give you a value in the keydown, then you could add Shell code to the
keydown event.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Debug.Print KeyCode
End Sub

GreenBug
09-08-2003, 11:03 AM
can you post the full code i would need to put into vb to get that to run i am afrade thats a bit above my ablities to inturprate that snipit as is it runs ok but i get no output

thanks

Ales Zigon
09-08-2003, 12:01 PM
When you run this code, open the immediate window (press Ctrl+G) or replace "Debug.Print" with MsgBox. This way you'll be able to see the result.

GreenBug
09-08-2003, 12:19 PM
thanks that worked but all 4 buttons return 255 is there a way to get deper into the system as there must be a way to distinguish between the 4 buttons

thanks fro all the help everyone

passel
09-08-2003, 01:48 PM
Well, there may be other ways, but I guess to see if using
GetAsyncKeyState directly is possible, I would just scan all 256
virtual keys to see if you are getting a unique code for those keys. Be
aware, once you start getting virtual keycodes, you will see mouse
buttons (as virtual keys 1, 2 and 4). If the codes are all 255 here, then
I guess I don't know how to read those keys. There may be some data
that can be gleaned from this Microsoft site, but I don't have time to
pursue it.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/KeyboardInput.asp

Try this code and see what numbers you get. Again I'm printing to
the debug.window, so you can adjust it however you see fit. I only had
a single button on the form, and when I ran the code, because the
button is the default (I guess), the loop started up without me having
to press the button. But you may have to press the button to start the
loop (I don't know). Pressing the Escape should end the program.

Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim p As Long
Static busy As Boolean
If Not busy Then
busy = True
Do
p = (p + 1) Mod 256
If GetAsyncKeyState(p) <> 0 Then
Debug.Print p
If p = 27 Then
Exit Do 'escape key
End If
End If
DoEvents 'Prevent Program from freezing up
Loop
busy = False
Unload Me
End If
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum