CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2001
    Posts
    391

    How do i get keycodes without having to press RETURN key (C# 1.1)

    I notice that in 1.1 there seems to be no way to get the user's key input, using the System.Console class's Read() function, without first hitting the enter key. I looked for other functions and in other classes and it doesnt seem possible in 1.1 ... How can something so basic and obvious be overlooked in 1.1 .. I do know that in 2.0+ ms finally added a ReadKey() function...

    Does anyone have an coding alternative for 1.1 users? (and saying: "upgrade" isnt what i am looking for).
    Last edited by quantass; July 12th, 2008 at 01:39 AM.

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Get Key Input without having to hit Return Key Possible? (C# 1.1)

    If you're looking for UI, use a form. You are in a Window's environment you know - that's what windows are there for.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Jan 2007
    Posts
    491

    Re: Get Key Input without having to hit Return Key Possible? (C# 1.1)

    Emm... I'm not so sure weater .NET 1.1 support it, but System.Runtime.InteropServices.Win32Interop._kbhit() returns 0 if a key was pressed or the key code otherwise.
    Code:
    using System.Runtime.InteropServices.Win32Interop;
    ...
    [DllImport("crtdll.dll")]
    public static extern int _kbhit();
    ...
    char ch;
    while((ch = _kbhit()) != 0);
    Console.WriteLine(ch.ToString());
    Helps somehow?

  4. #4
    Join Date
    Dec 2001
    Posts
    391

    Re: Get Key Input without having to hit Return Key Possible? (C# 1.1)

    Quote Originally Posted by Talikag
    Emm... I'm not so sure weater .NET 1.1 support it, but System.Runtime.InteropServices.Win32Interop._kbhit() returns 0 if a key was pressed or the key code otherwise.
    Code:
    using System.Runtime.InteropServices.Win32Interop;
    ...
    [DllImport("crtdll.dll")]
    public static extern int _kbhit();
    ...
    char ch;
    while((ch = _kbhit()) != 0);
    Console.WriteLine(ch.ToString());
    Helps somehow?
    THanks for taking the time to not only read my question but provide a useful answer!

  5. #5
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: How do i get keycodes without having to press RETURN key (C# 1.1)

    Maybe a thumb question: Why not simple upgrading to minimum 2.0 Framework. You now we already have 3.5 there
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  6. #6
    Join Date
    Dec 2001
    Posts
    391

    Re: How do i get keycodes without having to press RETURN key (C# 1.1)

    Quote Originally Posted by JonnyPoet
    Maybe a thumb question: Why not simple upgrading to minimum 2.0 Framework. You now we already have 3.5 there
    I was about to answer this question but realized there are numerous answers among my specific concern but then figured your question might have been rhetorical in nature and so i will just say a big thanks to Talitag for the assistance and by not resorting to what could have been the obvious.

  7. #7
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: How do i get keycodes without having to press RETURN key (C# 1.1)

    Quote Originally Posted by quantass
    I was about to answer this question but realized there are numerous answers among my specific concern but then figured your question might have been rhetorical in nature and so i will just say a big thanks to Talitag for the assistance and by not resorting to what could have been the obvious.
    No it wasn't really rethorical only, I wanted to suggest you that you really should think about this point. Maybe you have good reasons and I didn't expect to get all of them answered here, but is it a big deal to do so in your program ? ( for example changes in multithreading code behaviour )
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

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