Results 1 to 3 of 3

Thread: Spy++ and Sending Alt-Key Messages (HotKeys)

Threaded View

  1. #1

    Thread Starter
    Lively Member SpagettiProg's Avatar
    Join Date
    Dec 2004
    Location
    Miami, Florida
    Posts
    82

    Thumbs up Spy++ and Sending Alt-Key Messages (HotKeys)

    Hello everyone,

    Recently I had a big battle trying to send alt-f to a window (I was trying to automate some work for people at my job). I was using PostMessage and it would work fine with notepad, but not on the window that I needed. I did some digging on google and found people suggesting all sorts of crazy things....

    SendMessage, SendInput, keybd_event, PostMessage, SendKeys

    All these recommendations and no one providing some good working code.

    After doing some testing, I noticed that PostMessage and SendKeys works nicely when trying to send an alt-key message to a window.

    Below is both video instruction and working code. Please feel free to post the video on your site or share with anyone. It's free! Enjoy!



    http://www.silentthread.com/extras/AltToIE.avi (RIGHT-CLICK, SAVE TARGET AS

    Here is the codec to view the file....
    http://www.techsmith.com/download/codecs.asp




    VB Code:
    1. 'Code donated by SpegettiProg, AKA Numbchucks, AKA SiLentThReaD, AKA BLOW-T0RCH
    2. 'Feel free to distribute both code and video instruction
    3.  
    4.  
    5. Public Class Form1
    6.     Inherits System.Windows.Forms.Form
    7.  
    8. #Region " Windows Form Designer generated code "
    9.  
    10.     Public Sub New()
    11.         MyBase.New()
    12.  
    13.         'This call is required by the Windows Form Designer.
    14.         InitializeComponent()
    15.  
    16.         'Add any initialization after the InitializeComponent() call
    17.  
    18.     End Sub
    19.  
    20.     'Form overrides dispose to clean up the component list.
    21.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    22.         If disposing Then
    23.             If Not (components Is Nothing) Then
    24.                 components.Dispose()
    25.             End If
    26.         End If
    27.         MyBase.Dispose(disposing)
    28.     End Sub
    29.  
    30.     'Required by the Windows Form Designer
    31.     Private components As System.ComponentModel.IContainer
    32.  
    33.     'NOTE: The following procedure is required by the Windows Form Designer
    34.     'It can be modified using the Windows Form Designer.  
    35.     'Do not modify it using the code editor.
    36.     Friend WithEvents Button1 As System.Windows.Forms.Button
    37.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    38.         Me.Button1 = New System.Windows.Forms.Button
    39.         Me.SuspendLayout()
    40.         '
    41.         'Button1
    42.         '
    43.         Me.Button1.Location = New System.Drawing.Point(32, 24)
    44.         Me.Button1.Name = "Button1"
    45.         Me.Button1.Size = New System.Drawing.Size(248, 80)
    46.         Me.Button1.TabIndex = 0
    47.         Me.Button1.Text = "Alt to IE"
    48.         '
    49.         'Form1
    50.         '
    51.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    52.         Me.ClientSize = New System.Drawing.Size(328, 141)
    53.         Me.Controls.Add(Me.Button1)
    54.         Me.Name = "Form1"
    55.         Me.Text = "Form1"
    56.         Me.ResumeLayout(False)
    57.  
    58.     End Sub
    59.  
    60. #End Region
    61.  
    62.     Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    63.     (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    64.     Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
    65.     (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Int32, _
    66.     ByVal lParam As Int32) As Boolean
    67.     'Above we import 2 functions from user32
    68.  
    69.     Private Const WM_SYSKEYDOWN As Integer = &H104
    70.     Private Const WM_SYSKEYUP As Integer = &H105
    71.     'Above we specify the values of the for our WM_Messages
    72.  
    73.     Dim wParam As Integer
    74.     Dim lParam As Integer
    75.     'Above we declare our wParam and lParam
    76.  
    77.     Private Sub Button1_Click(ByVal sender As System.Object, _
    78.     ByVal e As System.EventArgs) _
    79.     Handles Button1.Click
    80.  
    81.         Dim IE_Handle As Integer 'Declaring our window handle
    82.         IE_Handle = FindWindow("IEFrame", vbNullString)
    83.         'Geting our window handle using the FindWindow function we imported.
    84.         'IEFrame is the class name of IE. You could have also
    85.         'used the title in place of
    86.  
    87.         AppActivate("Google")
    88.         'Not recommended to hard code anything, but this is just for testing sake.
    89.         'We active the IE window that has google open
    90.  
    91.         wParam = &H12
    92.         lParam = &H20380001
    93.         'Above we assign our params the values we got from spy++
    94.  
    95.  
    96.         PostMessage(IE_Handle, WM_SYSKEYDOWN, wParam, lParam)
    97.         PostMessage(IE_Handle, WM_SYSKEYUP, wParam, lParam)
    98.         'Above, we simulate a alt keystroke
    99.         SendKeys.Send("f")
    100.         SendKeys.Send("r")
    101.         'Above, we use SendKeys to active the properties window
    102.  
    103.     End Sub
    104.  
    105. End Class
    Last edited by SpagettiProg; Jun 15th, 2006 at 12:17 PM.
    If you feel my post has helped, please rate it
    http://www.silentthread.com

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