forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Use of GET_KEY_OR_YIELD@

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
mhudson



Joined: 05 Jan 2006
Posts: 18

PostPosted: Wed Jun 14, 2006 8:27 am    Post subject: Use of GET_KEY_OR_YIELD@ Reply with quote

Hi,

The help file suggests (to me) that this subroutine ought to work such that it is called repeatedly and only returns a key value if one is pressed, otherwise it does nothing. Perhaps I am wrong. Anyway, the following program:

Code:
program keyboardtest
implicit none

integer :: i

integer(kind=2) :: key

do i=1,1000000
write(*,*) i

call get_key_or_yield@(key)

key=0
if (key.ne.0) then
write(*,*) 'Key pressed with return value: ',key
end if
end do

end program keyboardtest


is supposed to loop over integers and display the key value each time a key is pressed. However, what actually happens is that the program prints '1' and then waits for me to press a key.

Have I simply misunderstood the use of the "yield" in this routine's name?

Mark.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7928
Location: Salford, UK

PostPosted: Wed Jun 14, 2006 9:36 am    Post subject: Use of GET_KEY_OR_YIELD@ Reply with quote

Mark

Why do you set key=0 after the call to get_key_or_yield@?
Otherwise it works OK.
Back to top
View user's profile Send private message AIM Address
mhudson



Joined: 05 Jan 2006
Posts: 18

PostPosted: Wed Jun 14, 2006 9:50 am    Post subject: Use of GET_KEY_OR_YIELD@ Reply with quote

Hi Paul,

Not sure why I had that KEY=0 where I did, it was supposed to be before the call to GET_KEY_OR_YIELD@.

In any case, the routine still causes the program to wait for a key to be pressed. The "YIELD" and the help file suggest that the program (i.e. the loop in this case) will run without the subroutine's getting in the way, until and unless a key is pressed.

Basically, the program prints the 1, then waits until I press a key, then prints the 2, then waits till I press a key. What I would like, and expected, is that the program will run through the loop, printing 1,2,3,... and the subroutine will intercept the keypress when it is made.

I have tried using ADD_KEYBOARD_MONITOR@, but this seems not to work with a console application.

The effect I am trying to achieve is to let the program (which is a console application) intercept, say, a Ctrl-D from the user, causing the program to dump useful output before the program then aborts itself.

Mark.
Back to top
View user's profile Send private message
brucebowler
Guest





PostPosted: Wed Jun 14, 2006 1:39 pm    Post subject: Use of GET_KEY_OR_YIELD@ Reply with quote

From the help description, it says "will yield control to other tasks", not "will return immediately if nothing's there". If the wording was carefully chosen (I can't say one way or the other whether it was or not), to me "other tasks" would be other programs or threads, not something else in "the same task".
Back to top
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7928
Location: Salford, UK

PostPosted: Thu Jun 15, 2006 12:25 am    Post subject: Use of GET_KEY_OR_YIELD@ Reply with quote

Yes, I think the yield is in the sense of a Windows exit to the main message queue.
There may also be a Windows "Sleep" element (to allow other threads a slice of time) but I would have to check the code for this.
This has little or no effect in a console executable but in a Windows executable it will allow the message queue to be processed, so that, for example, the mouse will continue to respond.
Back to top
View user's profile Send private message AIM Address
mhudson



Joined: 05 Jan 2006
Posts: 18

PostPosted: Thu Jun 15, 2006 2:05 am    Post subject: Use of GET_KEY_OR_YIELD@ Reply with quote

Thanks for the responses. The upshot is just that I'd misunderstood the help file description. But can I go back to the other part of my question and ask if there is any way to get a console application to respond to a key combination if it is pressed, but to continue doing other things in the program if not? There are a number of Salford commands that deal with keyboard input, but they seem to require a Clearwin window or other window for which one can obtain the handle.

Failing that, has anyone out there been able to trap, for instance, a Ctrl-C in a console application by other means? Or is this sort of thing just not possible? Windows API-based ideas are welcome. I'll go off and browse the MSDN myself now.

Mark
Back to top
View user's profile Send private message
mhudson



Joined: 05 Jan 2006
Posts: 18

PostPosted: Thu Jun 15, 2006 2:26 am    Post subject: Use of GET_KEY_OR_YIELD@ Reply with quote

Hi again,

Well, it seems that the example program given in the SET_TRAP@ function's documentation works as I had desired for trapping a Ctrl-C or Ctrl-Break, so you can close this correspondence if you like.

Unless, anyone has any other comments about how I might trap non-CtrlC key presses in a console application?

Mark
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7928
Location: Salford, UK

PostPosted: Thu Jun 15, 2006 6:04 am    Post subject: Use of GET_KEY_OR_YIELD@ Reply with quote

Mark

The following may be of interest....
[start up and then press the 'A' key]

include <win32api.ins>
integer*2 state,oldstate
oldstate = 0
do
state = GetKeyState(ichar('A'))
if(state /= oldstate) then
print*, state
oldstate = state
endif
enddo
end
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group