Go to Post Mr.Lavery You Make My Day - Rohith Surampudi [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #46   Spotlight this post!  
Unread 07-06-2002, 17:43
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
grr, i tried my mess of a program out today, and it didn't work. there seems to have been a problem with writing to a file. i' not sure why, but that seems to be where the error was from. there was no syntax errors, so there was something wrong somewhere else. could i actually need two threads? in that case, i think i know what to do, i just need someone to help me on what method i need to take.
__________________
AIM --> Woloi
Email --> ian@woloschin.com
  #47   Spotlight this post!  
Unread 07-06-2002, 18:31
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
I'd be happy to help. Just send your source code my way, and I'll help with any parts you need. ICQ: 152894206 (file transfers probably won't work, but just attach them to a message here, and I'll take a look.)
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #48   Spotlight this post!  
Unread 07-06-2002, 19:37
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
How to monitor the keyboard without blocking on every cycle? Try in_avail()

Quote:
Originally posted by Ian W.
ok thanks. only one more problem then. how can i moniter the keyboard without stopping every loop cycle? i know about cin and fin (fstream). that's all. both stop until data is put in and the 'enter' key is hit. that wouldn't do. there must be some way around this, anyone know how? cause if that works, then the program will actually work better than i expected
I haven't tried this with C++, but in C you use kbhit(). It's possible this might work in C++ too, but it's risky.

Check out in_avail. That may do what you want. I believe if you call cin.in_avail() it will return > 0 if a key has been struck. You can simply avoid doing the keyboard read if there's nothing to read.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
  #49   Spotlight this post!  
Unread 07-06-2002, 21:53
VanWEric VanWEric is offline
Registered User
#0250 (Dynamos)
 
Join Date: Feb 2002
Location: NY
Posts: 86
VanWEric is an unknown quantity at this point
keybd_event

I wrote 2 apps that talked to eachother (just for fun). One app used kb_event() to put keyboard events out for the other to pick up with getch(). Basically, do keybd_event(VK_(a letter or function),0,0,0); Have the recieving proggie active, use getch and look at the char it returns. IE to send the letter A to the other progg have app 1 go keybd_event(VK_A,0,0,0). The other is waiting with a myrecievingchar = getch(); I wrote a header file to include the letters and numbers (( windows.h has all the kb_event crap, but only defines the keys that arent useful)) I can get that posted if you want it, but it is really just a bunch of #define VK_A 65, #define VK_B...
Oh, and getch is in conio.h

Hope that helped, but i am guessing it didnt.

Mayhaps the unique data sending approach was vaguely interesting though
  #50   Spotlight this post!  
Unread 07-06-2002, 22:02
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
hmm, i tried the in_avail thing, and it doesn't work. heck, it's not even recognized by my compiler (VC++). as for the rest of my code, i don't use ICQ, so the number you gave me means nothing to me . if you want, i do have AIM (yeah, i hate AOL too).
__________________
AIM --> Woloi
Email --> ian@woloschin.com
  #51   Spotlight this post!  
Unread 07-06-2002, 22:31
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Quote:
Originally posted by Ian W.
hmm, i tried the in_avail thing, and it doesn't work. heck, it's not even recognized by my compiler (VC++). as for the rest of my code, i don't use ICQ, so the number you gave me means nothing to me . if you want, i do have AIM (yeah, i hate AOL too).
As far as I can tell, in_avail is not non-standard or a new feature. Try calling cin.rdbuf( )->in_avail( ) instead of cin.in_avail( ). I assume you must already be #including <iostream>.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
  #52   Spotlight this post!  
Unread 07-06-2002, 22:38
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
hmm, that syntax works, but how would i run that in a while loop? like, what number does 'cin.rdbuf( )->in_avail( )' equal when no key is pressed? i'm not sure of that.
__________________
AIM --> Woloi
Email --> ian@woloschin.com
  #53   Spotlight this post!  
Unread 07-06-2002, 23:14
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
ok, i've figured out the 'cin.rdbuf( )->in_avail( )' line seems to always equal 0, no matter what i do. how do i change this?
__________________
AIM --> Woloi
Email --> ian@woloschin.com
  #54   Spotlight this post!  
Unread 07-06-2002, 23:21
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
after you've done the cin.rdbuf( )->in_avail( ), you must actually read in a byte. a simple 'cin>>myChar' should do nicely. the problem is, in_avail() on checks to see if data is there, it doesn't clear it from the buffer. Therefore, that same data will be there the next time and you will always get 0 back. If you're already doing this, post the offending code and I'll take a look at it.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #55   Spotlight this post!  
Unread 07-06-2002, 23:33
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
is there anyway for the computer to skip the cin>>myChar if no data is entered? cause otherwise, the loop will stop once every cycle for me to hit enter. that's no good. could i use the 'keybd_event(i,0,0,0);' event to hit enter, if no data is entered? my whole problem hinges around the fact that i know no way of skipping a cin without putting in data. any help?
__________________
AIM --> Woloi
Email --> ian@woloschin.com
  #56   Spotlight this post!  
Unread 08-06-2002, 00:13
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
I think I've got the solution...

Going back to a previous post (by gwross), your best method will be to use kbdhit(). It will return 0 if no key has been pressed, and 1 if a key has been pressed. Since I assume you only want it to quit when a certain key is pressed, you can then issue a getch() which will return the key that was pressed. Just compare it, and you should be good to go. Just make sure to include <conio.h>.
Here's the code I tested it with:
while(true){
if(kbdhit()){
cout<<"key pressed:";
myChar=getch();
cout<<myChar<<"\n";
if(myChar=='q')
return 0;
}
else{
cout<<"no key pressed\n";
}
cout.sync_with_stdio()
}

BTW, that cout.sync_with_stdio() is because I was having problems with the output being very sluggish.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #57   Spotlight this post!  
Unread 08-06-2002, 17:46
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Quote:
It wasn't me! I got the picture in an email, and I think the billboard was somewhere in England
I wasn't trying to imply that it was you by any means...

Last edited by Dave Flowerday : 08-06-2002 at 17:49.
  #58   Spotlight this post!  
Unread 10-06-2002, 01:19
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Quote:
Originally posted by Ian W.
ok, i've figured out the 'cin.rdbuf( )->in_avail( )' line seems to always equal 0, no matter what i do. how do i change this?
cin.rdbuf( )->in_avail( ) should return non zero (greater than zero) if there is data in the keyboard buffer. Is this not the case? When you say "no matter what i do" does that include pressing keyboard keys (other than Ctrl-C which is probably handled differently than other keys)? (I know that may sound insulting. That's not my intention. I have worked on a help line, and I've learned to not take anything for granted.) If you are able to read data from the keyboard using cin, then in_avail() should also work.

BTW, for readability (probably not efficiency) you could save the return value of cin.rdbuf() in a variable (say cinBuffer) -- outside the loop and then only call cinBuffer->in_avail() inside the loop.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
  #59   Spotlight this post!  
Unread 10-06-2002, 01:33
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
I've been playing around with this too, and I've run into the same problems. It seems that the only way to get data to cin so that in_avail() will notify you is to do a cin! For example, if you call cin<<x, but at the prompt type something like "5 10 15", then in_avail() will return the number of chars that are still in the buffer. In this case, either 6 or 7 (I can't remember which), because the first one has been eaten by your cin statement. As far as I can tell, this would be useful in figuring out how much data a user input, but only after the user actually input the data.

Or I could be completely wrong... Anyway, the code I posted above seems to work (based on your earlier suggestion). If anyone can get this working with cin, I'd be interested to hear how.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #60   Spotlight this post!  
Unread 10-06-2002, 17:51
Ian W. Ian W. is offline
College? What?
no team (Gompei and the Herd)
Team Role: College Student
 
Join Date: Jan 2002
Rookie Year: 2002
Location: Worcester, MA | Smithtown, NY
Posts: 1,464
Ian W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to allIan W. is a name known to all
Send a message via AIM to Ian W.
well, i tried the _getch () and _getche () functions (from conio.h). just a simple loop to test it, and it worked pefectly, doing exactly what i wanted. from what i understand, it reads the I/O stream, and you don't even have to hit enter. it will just go on and on until there is input on the keyboard, i think. if that's the case, i just need to identify a certain key, and all should work as i want.
__________________
AIM --> Woloi
Email --> ian@woloschin.com
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Win32 serial port - recieve buffer seanwitte Programming 4 05-11-2003 21:41
White Paper Discuss: FIRST Editor v1.2 CD47-Bot Extra Discussion 1 18-09-2003 19:32
How to communicate both through radio and serial port? JC Denton Programming 1 08-02-2003 23:43
Ever seen this serial port problem before??? Aidan F. Browne Programming 5 05-02-2003 12:03
serial communication using c++ Malakili Programming 31 01-05-2002 15:51


All times are GMT -5. The time now is 10:32.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi