CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: SendKey problem

  1. #1
    Join Date
    May 2008
    Posts
    31

    Post SendKey problem

    I tried this sendkey but my PC has frozen. By the way I used XP windows and Microsoft Visual Basic 2005 Express Edition v2.

    Code:
    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown 
    
    System.Windows.Forms.SendKeys.Send("%+")  
     
     End Sub

  2. #2
    Join Date
    Aug 2005
    Location
    Spain!
    Posts
    149

    Talking Re: SendKey problem

    Hi nader!, i've not tested but, try this way

    Code:
    System.Windows.Forms.SendKeys.Send("%{ADD}")
    If your combination is ALT + Plus this may work

  3. #3
    Join Date
    May 2008
    Posts
    31

    Re: SendKey problem

    It caused same probelm.

  4. #4
    Join Date
    Aug 2005
    Location
    Spain!
    Posts
    149

    Red face Re: SendKey problem

    My code is now tested and works fine, maybe it's a problem with another program that fires when this especific key combination is pressed.. it hangs too when you press Alt + Plus with keyboard?

  5. #5
    Join Date
    May 2008
    Posts
    31

    Re: SendKey problem

    How do you make shift with alt.

  6. #6
    Join Date
    Aug 2005
    Location
    Spain!
    Posts
    149

    Smile Re: SendKey problem

    Here's the SendKey class help

    http://msdn.microsoft.com/en-us/libr....sendkeys.aspx

    In it you can find all the keycodes and combinations.

    The code of the shift is '+' and the alt code is '%'

  7. #7
    Join Date
    May 2008
    Posts
    31

    Re: SendKey problem

    I didn't know how to get useful from this link...I'm newbie.
    but I found the prblem is:
    when I put this coede in the textbox in down event it gives me many result without stopping the project. but when I execute the code from the button click it generetd one teim, os the problem was in the textbox. How can I set this code to textbox form anohter plce like button click?

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: SendKey problem

    try the Lost_Focus Event. As soon as you tab off, it executes
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: SendKey problem

    Quote Originally Posted by nader
    I didn't know how to get useful from this link...I'm newbie.
    but I found the prblem is:
    when I put this coede in the textbox in down event it gives me many result without stopping the project. but when I execute the code from the button click it generetd one teim, os the problem was in the textbox. How can I set this code to textbox form anohter plce like button click?
    Sendkeys simply sends keystrokes to the active application, to the best of my knowledge they can not be targeted and work just like the user actually typed from the keyboard. Text always goes where the cursor is.

    In your code you placed the code in the keydown event and since the system sees this as a keyboard entry it will execute the keydown event until the program crashes or is halted.

    It the textbox is in your program why not just simply set the text property of the text box? Although ALT + Shift + + does not result in a character. Not sure why you need to send this to a textbox within your program In fact I can't think of any reason at all to do so.

  10. #10
    Join Date
    May 2008
    Posts
    31

    Re: SendKey problem

    The tip of pointer doesn't show like this ( as it show in the Pic) only if I use the Alt+Shift
    Attached Images Attached Images  

  11. #11
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: SendKey problem

    Sendkeys simply sends keystrokes to the active application, to the best of my knowledge they can not be targeted and work just like the user actually typed from the keyboard. Text always goes where the cursor is.
    True, and is exactly why it's such a bad idea.
    However, there is a module that does target a particular window, without interfering with the user's keyboard focus.

    SendKeys(with directive focus)

    However, I think there is another solution to nader's problem, if I could only fully understand it first. lol
    EDIT:
    You can make the text go right to left, by setting the textbox's property for that.
    Code:
    TextBox1.TextAlign = HorizontalAlignment.Right
    Please elaborate.
    Last edited by TT(n); October 23rd, 2008 at 02:26 PM.

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

Featured