Results 1 to 9 of 9

Thread: [2.0] A hopefully easy question about forms

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    [2.0] A hopefully easy question about forms

    Alright I would like to know how to approach having your form respond to keys pressed on the keyboard when the form is not active.


    Here's an example. You know how some macro programs have press F8 or some key like that to start the current macro? And you can press F8 even when the window is not maximized or active! How would I do this? Here's all I want to know:

    Question: When a form is minimized or just not active and you press F8 on the keyboard, how can I make a messagebox come up? I should be able to fiqure out the rest.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] A hopefully easy question about forms

    Here's some good information, plus a search for the appropriate terms will provide more.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2.0] A hopefully easy question about forms

    muchos gracios! works great

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2.0] A hopefully easy question about forms

    wait.. i need ALL this code just to do this small simple thing? I cannot even put all the code in here! "The text that you have entered is too long (39630 characters). Please shorten it to 10000 characters long." Ouch. Well I'll try to shorten it

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] A hopefully easy question about forms

    I haven't looked at the code involved but I very much doubt that you need that much. At a glance it looks like that article provides a class that wraps the interaction with the Windows API. If that's the case then the author has already done the hard work for you and all you need to do is create an instance of that class and access its members. The alternative is to declare the API functions yourself. That would still not take as much code as you mention because it would be specific to your situation, not for the general case as that author is trying to provide, but it would be more complex than simply using a single managed class.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2.0] A hopefully easy question about forms

    Yes but the thing is that this program will be processing so many keyboard buttons every single millisecond and often it makes the computer slow down as it is. If I had a lot more code then it'd probably crash the computer or something considering the memory use. There isn't just an easy way to make it so IF and application is running AND you press F8, THEN a MessageBox executes? I don't think doing just that should take that much.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] A hopefully easy question about forms

    Quote Originally Posted by Fromethius
    There isn't just an easy way to make it so IF and application is running AND you press F8, THEN a MessageBox executes? I don't think doing just that should take that much.
    That's being a bit naive. Why should every application be aware of the input to every other application? If that was the case then everything would always be slower because every application would have to process all input. In the grand scheme of things it's a rare thing for an application to have to respond to keyboard input when it's not active. There is a way to do it, and that way is with keyboard hooks.

    I doubt that your user is pressing multiple keys per millisecond so this application of yours must be very unusual. To assume that something should be able to be done just because you want it to be is unrealistic.

    I've never set a keyboard hook myself (because, like the majority, I've never had need) so I don't know everything that's involved but from what I do understand of it it should take thousands of lines of code. I think you need to look into it a bit deeper and understand exactly what is involved. As I said, you can find other relevant information by searching now that you know the correct key words to search for.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2.0] A hopefully easy question about forms

    Alright, and the REASON I am doing this is because I am making a macro program. And yea, I'll look into Keyboard hooks and I also did last night and it seems sooo freaking long. I can, no problem, get it to work right this minute, but is it really worth 40000 lines of code?

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] A hopefully easy question about forms

    Quote Originally Posted by jmcilhinney
    I've never set a keyboard hook myself (because, like the majority, I've never had need) so I don't know everything that's involved but from what I do understand of it it should take thousands of lines of code.
    Oops. I badly misrepresented my case there. I actually meant that it should NOT take thousands of lines of code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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