Results 1 to 6 of 6

Thread: plz tell me whats wrong

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    15
    i'm making a key code so when someone hits the button 'A' on their keyboard, my program will go to http://www.aol.com (for example) .. this is what i have:


    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    'If different Keys are pressed then set the URL to different websites
    If KeyCode = vbKeyA Then URL = "www.vb-world.net"
    If KeyCode = vbKeyUp Then URL = "www.hotmail.com"
    If URL <> "" Then
    'Open the website specified in URL in WebBrowser1
    WebBrowser1.Navigate URL
    End If
    End Sub


    And I also tried:

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 97 Then WebBrowser1.Navigate("http://www.aol.com")
    End Sub

    i hope these 2 are even close, but both didn't work..
    plz tell me whats wrong..

    ((VB 6))

  2. #2
    Addicted Member
    Join Date
    Jan 1999
    Posts
    204
    hey try this
    Code:
    Private Sub Form_KeyPress(KeyAscii As Integer)
    if keyascii = vbkeya then
    webcontrol.navacate = "www.aol.com"
    elseif keyascii = vbkeyb then
     
    End Sub
    i think that might be it if you want mre info icq me or aim me ok i got a keyascii program around here i will send it to you , but tahst how you whould do that kinda stuff
    WHat would we do with out Microsoft.
    A lot more.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    15

    not workin :(

    nope, that didn't work.. this is tricky, someone plz help!

    its for VB 6, remember that

  4. #4
    Addicted Member
    Join Date
    Jan 1999
    Posts
    204
    hey what is the error for your code i think you cant haev it in the form keypress because then they will have to click on the form then puch it do put it like in the address box like this

    Code:
    adreesbox_KeyDown
    If KeyCode = vbKeyA Then URL = "www.vb-world.net" 
    If KeyCode = vbKeyUp Then URL = "www.hotmail.com" 
    If URL <> "" Then 
    'Open the website specified in URL in WebBrowser1 
    WebBrowser1.Navigate URL 
    End If
    tasht an example but try to but it somewhere they whould click alot like the webbroswer control it self
    WHat would we do with out Microsoft.
    A lot more.

  5. #5
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    Try this

    Code:
    Select Case Ascii(KeyCode)
      Case "a","A"
        Url="www.aol.com"
      Case "b","B"
        Url="bbc.co.uk"
    End Select
    DocZaf
    {;->

  6. #6
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    If you want to do this from anywhere in Windows, (not just when your app has focus), then setup a HotKey using the API's, i.e.

    In a Module:
    Code:
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
    Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
    
    Private Const WM_HOTKEY = &H312
    
    Private Const MOD_ALT = &H1
    Private Const MOD_CONTROL = &H2
    Private Const MOD_SHIFT = &H4
    
    Private Const GWL_WNDPROC = (-4)
    
    Private lPrevWnd As Long
    Private lHwnd As Long
    Private lHotKeys As Long
    
    Public Sub SetHotKey(ByVal hWnd As Long, ByVal lID As Long, ByVal lModifier As Long, ByVal lKey As Long)
        'Create a HotKey, if it's the 1st one, Subclass the Form to be able to Capture the HotKeys...
        If lPrevWnd = 0 Then
            'Subclass the Form diverting all message to our "SubWindow()" function
            lHwnd = hWnd
            lPrevWnd = SetWindowLong(lHwnd, GWL_WNDPROC, AddressOf SubWindow)
        End If
        'Register the HotKey with Windows
        Call RegisterHotKey(lHwnd, lID, lModifier, lKey)
        'Keep track of the No. of HotKeys
        lHotKeys = lHotKeys + 1
    End Sub
    
    Public Sub RemoveHotKey(ByVal lID As Long)
        'Remove the HotKey, if it was the last one, remove the Form Subclassing
        Call UnregisterHotKey(lHwnd, lID)
        lHotKeys = lHotKeys - 1
        If lHotKeys = 0 Then Call SetWindowLong(lHwnd, GWL_WNDPROC, lPrevWnd)
    End Sub
    
    Private Function SubWindow(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        'Check for the HotKey Message and take action depending on which HotKey is pressed
        If Msg = WM_HOTKEY Then
            Select Case wParam
            Case 1
                'Navigate to AOL
                Form1.WebBrowser1.Navigate "www.aol.com"
                'Bring the Form to the Front of Windows
                Call SetForegroundWindow(lHwnd)
                
            Case 2
                'Etc..
                
            End Select
        End If
        'Pass on the Message to the Default Window Message Handler
        SubWindow = CallWindowProc(lPrevWnd, hWnd, Msg, wParam, ByVal lParam)
    End Function
    Example usage:
    Code:
    Private Sub Form_Load()
        'Set a Hotkey up for the "A" Key
        Call SetHotKey(hWnd, 1, 0, vbKeyA)
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        'Remove the HotKey
        Call RemoveHotKey(1)
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width