- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear all,
I would like to know how to let fortran read " enter " key.
Regards
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
to READ the keyboard:
Use the following in a new console project to demonstrate it:
PROGRAM READENTER
USE DFLIB
CHARACTER(1) MYINPUT
INTEGER RESULT
DO WHILE (.TRUE.)
MYINPUT=GETCHARQQ()
IF(MYINPUT.EQ.CHAR(13) ) PRINT *, 'CARRIAGE RETURN'
IF(MYINPUT == "X".OR.MYINPUT == "x") EXIT
END DO
END PROGRAM
However, your post title mentions 'press' the Enter key.
In that case, are you wanting to send an 'enter key has been pressed' message from within
your program to some part of your program or to some other program which must act on it, without actually
having to physically press the ';Enter' key?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try this program, which posts a 'WM_KEYDOWN' message to the console when the 'E' key is pressed and after the 'E' (or 'e') is displayed
in the console window. The message results in GETCHARQQ picking up the 'Enter' message and subsequently displaying 'CARRIAGE RETURN'.
PROGRAM READENTER
use dfwin
USE DFLIB
CHARACTER(1) MYINPUT
INTEGER result, hwnd
! Give your console window a nice title and add a short delay to let the title take
result=SetConsoleTitle('My Enter program'c)
call sleep(40)
! Get the handle to the console window that has your title
hwnd=FindWindow('ConsoleWindowClass'c,'My Enter program'c)
! Enter the loop to test what is coming in from the keyboard.
! press some keys to exercise the program, including the 'Enter' key...
DO WHILE (.TRUE.)
MYINPUT=GETCHARQQ()
IF(MYINPUT.EQ.CHAR(13) ) PRINT *, 'CARRIAGE RETURN'
IF(MYINPUT == "X".OR.MYINPUT == "x") EXIT ! To exit the infinite loop when required
! to test the PostMessage method, press the 'E' key to send an 'Enter' message
IF(MYINPUT == "E".OR.MYINPUT == "e") then
! Send a message to the console window's message queue that the 'Enter' key has been pressed
! use PostMessage instead of SendMessage as Postmessage returns immediately
! 13 is the virtual key code for the 'Enter' key and it is put into the low order bits of the WPARAM.
! 28 is the scan key code for it and it is put into the high order bits of the LPARAM.
! 0 is the repeat code and is put into nthe low order bits of the LPARAM
RESULT=POSTMESSAGE(hwnd, WM_KEYDOWN,MAKEWPARAM(13,0),MAKELPARAM(0,28))
ENDIF
PRINT *,MYINPUT
END DO
END PROGRAM
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page