{\rtf1\adeflang1025\ansi\ansicpg936\uc2\adeff0\deff0\stshfdbch13\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe2052{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f13\fnil\fcharset134\fprq2{\*\panose 02010600030101010101}\'cb\'ce\'cc\'e5{\*\falt SimSun};} {\f18\fmodern\fcharset136\fprq1{\*\panose 02020309000000000000}MingLiU{\*\falt \'b2\'d3\'a9\'fa\'c5\'e9};}{\f36\fnil\fcharset134\fprq2{\*\panose 02010600030101010101}@\'cb\'ce\'cc\'e5;} {\f82\fmodern\fcharset136\fprq1{\*\panose 02020309000000000000}@MingLiU;}{\f179\froman\fcharset238\fprq2 Times New Roman CE;}{\f180\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f182\froman\fcharset161\fprq2 Times New Roman Greek;} {\f183\froman\fcharset162\fprq2 Times New Roman Tur;}{\f184\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f185\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\f186\froman\fcharset186\fprq2 Times New Roman Baltic;} {\f187\froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\f311\fnil\fcharset0\fprq2 SimSun Western{\*\falt SimSun};}{\f361\fmodern\fcharset0\fprq1 MingLiU Western{\*\falt \'b2\'d3\'a9\'fa\'c5\'e9};} {\f541\fnil\fcharset0\fprq2 @\'cb\'ce\'cc\'e5 Western;}{\f1001\fmodern\fcharset0\fprq1 @MingLiU Western;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0; \red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;\red255\green153\blue0;} {\stylesheet{\qj \li0\ri0\nowidctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs24\alang1025 \ltrch\fcs0 \fs21\lang1033\langfe2052\kerning2\loch\f0\hich\af0\dbch\af13\cgrid\langnp1033\langfenp2052 \snext0 Normal;} {\*\cs10 \additive \ssemihidden Default Paragraph Font;}{\* \ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\trcbpat1\trcfpat1\tblind0\tblindtype3\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv \ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs20 \ltrch\fcs0 \fs20\lang1024\langfe1024\loch\f0\hich\af0\dbch\af13\cgrid\langnp1024\langfenp1024 \snext11 \ssemihidden Normal Table;}{ \s15\qc \li0\ri0\nowidctlpar\brdrb\brdrs\brdrw15\brsp20 \tqc\tx4153\tqr\tx8306\wrapdefault\aspalpha\aspnum\faauto\nosnaplinegrid\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs18\alang1025 \ltrch\fcs0 \fs18\lang1033\langfe2052\kerning2\loch\f0\hich\af0\dbch\af13\cgrid\langnp1033\langfenp2052 \sbasedon0 \snext15 \styrsid15098623 header;}{\s16\ql \li0\ri0\nowidctlpar \tqc\tx4153\tqr\tx8306\wrapdefault\aspalpha\aspnum\faauto\nosnaplinegrid\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs18\alang1025 \ltrch\fcs0 \fs18\lang1033\langfe2052\kerning2\loch\f0\hich\af0\dbch\af13\cgrid\langnp1033\langfenp2052 \sbasedon0 \snext16 \styrsid15098623 footer;}{\*\cs17 \additive \rtlch\fcs1 \af0 \ltrch\fcs0 \ul\cf2 \sbasedon10 \styrsid15098623 Hyperlink;}}{\*\latentstyles\lsdstimax156\lsdlockeddef0}{\*\pgptbl {\pgp\ipgp0\itap0\li0\ri0\sb0\sa0}}{\*\rsidtbl \rsid655764 \rsid811358\rsid1069012\rsid1074055\rsid1318786\rsid1462542\rsid2231290\rsid2847010\rsid2909350\rsid3146529\rsid3152368\rsid3153644\rsid3409549\rsid3869496\rsid4001084\rsid4197693\rsid4419642\rsid4477090\rsid5848812\rsid6441775\rsid6492656\rsid6493368 \rsid7939098\rsid8674677\rsid8869018\rsid8944438\rsid9449096\rsid10106844\rsid10236727\rsid10246904\rsid10505668\rsid10707375\rsid10897542\rsid11282186\rsid11941893\rsid12669821\rsid13312263\rsid13773176\rsid14707564\rsid14892288\rsid15098623\rsid15222873 \rsid15611782\rsid15665703\rsid15817367\rsid15866361\rsid16080730\rsid16195404\rsid16517661\rsid16546564\rsid16607898}{\*\generator Microsoft Word 11.0.0000;}{\info{\title +-----------------------------------------------+}{\subject +-----------------------------------------------+}{\author Document Search} {\keywords Document Search}{\doccomm http://www.downhi.com/txt/YBU77gDs3ChK.html}{\operator www.downhi.com}{\creatim\yr2010\mo9\dy28\hr22\min9}{\revtim\yr2014\mo4\dy4\hr1\min23}{\version26}{\edmins1077}{\nofpages1}{\nofwords27}{\nofchars168}{\*\manager http://www.downhi.com/} {\*\company http://www.downhi.com/}{\*\category Document Search}{\nofcharsws186}{\vern24617}{\*\password 00000000}}{\*\xmlnstbl {\xmlns1 http://schemas.microsoft.com/office/word/2003/wordml}{\xmlns2 urn:schemas-microsoft-com:office:smarttags}} \paperw11906\paperh16838\margl1134\margr1134\margt1134\margb1134\gutter0\ltrsect \deftab420\ftnbj\aenddoc\donotembedsysfont1\donotembedlingdata0\grfdocevents0\validatexml1\showplaceholdtext0\ignoremixedcontent0\saveinvalidxml0\showxmlerrors1\formshade\horzdoc\dgmargin\dghspace180\dgvspace156\dghorigin1134\dgvorigin1134\dghshow0 \dgvshow2\jcompress\lnongrid\viewkind1\viewscale85\splytwnine\ftnlytwnine\htmautsp\useltbaln\alntblind\lytcalctblwd\lyttblrtgr\lnbrkrule\nobrkwrptbl\snaptogridincell\allowfieldendsel\wrppunct\asianbrkrule\rsidroot3869496\newtblstyruls\nogrowautofit {\*\fchars !),.:\'3b?]\'7d\'a1\'a7\'a1\'a4\'a1\'a6\'a1\'a5\'a8\'44\'a1\'ac\'a1\'af\'a1\'b1\'a1\'ad\'a1\'c3\'a1\'a2\'a1\'a3\'a1\'a8\'a1\'a9\'a1\'b5\'a1\'b7\'a1\'b9\'a1\'bb\'a1\'bf\'a1\'b3\'a1\'bd\'a3\'a1\'a3\'a2\'a3\'a7\'a3\'a9\'a3\'ac\'a3\'ae\'a3\'ba\'a3\'bb\'a3\'bf\'a3\'dd\'a3\'e0\'a3\'fc\'a3\'fd\'a1\'ab\'a1\'e9 }{\*\lchars ([\'7b\'a1\'a4\'a1\'ae\'a1\'b0\'a1\'b4\'a1\'b6\'a1\'b8\'a1\'ba\'a1\'be\'a1\'b2\'a1\'bc\'a3\'a8\'a3\'ae\'a3\'db\'a3\'fb\'a1\'ea\'a3\'a4}\fet0{\*\wgrffmtfilter 013f}\ilfomacatclnup0{\*\template C:\\Documents and Settings\\Administrator\\\'d7\'c0\'c3\'e6\\doc.dot}{\*\ftnsep \ltrpar \pard\plain \ltrpar\qj \li0\ri0\nowidctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs24\alang1025 \ltrch\fcs0 \fs21\lang1033\langfe2052\kerning2\loch\af0\hich\af0\dbch\af13\cgrid\langnp1033\langfenp2052 {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid14707564 \chftnsep \par }}{\*\ftnsepc \ltrpar \pard\plain \ltrpar\qj \li0\ri0\nowidctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs24\alang1025 \ltrch\fcs0 \fs21\lang1033\langfe2052\kerning2\loch\af0\hich\af0\dbch\af13\cgrid\langnp1033\langfenp2052 {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid14707564 \chftnsepc \par }}{\*\aftnsep \ltrpar \pard\plain \ltrpar\qj \li0\ri0\nowidctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs24\alang1025 \ltrch\fcs0 \fs21\lang1033\langfe2052\kerning2\loch\af0\hich\af0\dbch\af13\cgrid\langnp1033\langfenp2052 {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid14707564 \chftnsep \par }}{\*\aftnsepc \ltrpar \pard\plain \ltrpar\qj \li0\ri0\nowidctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs24\alang1025 \ltrch\fcs0 \fs21\lang1033\langfe2052\kerning2\loch\af0\hich\af0\dbch\af13\cgrid\langnp1033\langfenp2052 {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid14707564 \chftnsepc \par }}\ltrpar \sectd \ltrsect\linex0\headery851\footery992\colsx425\endnhere\sectlinegrid312\sectspecifyl\sectrsid6493368\sftnbj {\headerr \ltrpar \pard\plain \ltrpar\s15\qc \li0\ri0\nowidctlpar\brdrb\brdrs\brdrw15\brsp20 \tqc\tx4153\tqr\tx8306\wrapdefault\aspalpha\aspnum\faauto\nosnaplinegrid\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af0\afs18\alang1025 \ltrch\fcs0 \fs18\lang1033\langfe2052\kerning2\loch\af0\hich\af0\dbch\af13\cgrid\langnp1033\langfenp2052 {\rtlch\fcs1 \af0\afs30 \ltrch\fcs0 \b\f13\fs30\cf6\insrsid1074055\charrsid1074055 \hich\af13\dbch\af13\loch\f13 Free Document Search and Download}{\rtlch\fcs1 \af0\afs30 \ltrch\fcs0 \b\fs30\cf6\loch\af13\insrsid6493368\charrsid1074055 \par }{\field{\*\fldinst {\rtlch\fcs1 \af0\afs32 \ltrch\fcs0 \f13\fs32\cf6\insrsid14892288 \hich\af13\dbch\af13\loch\f13 HYPERLINK "http://www.downhi.com/" }{\rtlch\fcs1 \af0\afs32 \ltrch\fcs0 \fs32\cf6\loch\af13\insrsid10707375\charrsid14892288 {\*\datafield 00d0c9ea79f9bace118c8200aa004ba90b0200000003000000e0c9ea79f9bace118c8200aa004ba90b4e00000068007400740070003a002f002f00770065006e00640061006e0067002e0064006f00630073006f0075002e0063006f006d002f000000795881f43b1d7f48af2c825dc485276300000000a5ab0000000000}} }{\fldrslt {\rtlch\fcs1 \af0\afs32 \ltrch\fcs0 \cs17\f13\fs32\ul\cf2\insrsid3146529\charrsid14892288 \hich\af13\dbch\af13\loch\f13 http://www.downhi.com/}}}\sectd \linex0\endnhere\sectdefaultcl\sftnbj {\rtlch\fcs1 \af0\afs32 \ltrch\fcs0 \fs32\cf6\loch\af13\insrsid6493368\charrsid15098623 \par }}{\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta \dbch .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang {\pntxta \dbch .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta \dbch .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta \dbch )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb \dbch (}{\pntxta \dbch )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb \dbch (}{\pntxta \dbch )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb \dbch (} {\pntxta \dbch )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb \dbch (}{\pntxta \dbch )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb \dbch (}{\pntxta \dbch )}}\pard\plain \ltrpar\qj \li0\ri0\sl180\slmult0 \nowidctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid6493368 \rtlch\fcs1 \af0\afs24\alang1025 \ltrch\fcs0 \fs21\lang1033\langfe2052\kerning2\loch\af0\hich\af0\dbch\af13\cgrid\langnp1033\langfenp2052 {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid6493368\charrsid1074055 \loch\af0\hich\af0\dbch\f13 \'a1\'a1\'a1\'a1}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid6493368\charrsid1074055 \par }\pard \ltrpar\qc \li0\ri0\sl180\slmult0\nowidctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid1318786 {\rtlch\fcs1 \af0\afs36 \ltrch\fcs0 \b\fs36\insrsid1318786\charrsid1074055 \hich\af0\dbch\af13\loch\f0 +-----------------------------------------------+ \par }\pard \ltrpar\qj \li0\ri0\sl180\slmult0\nowidctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid1074055 {\rtlch\fcs1 \af0 \ltrch\fcs0 \fs24\insrsid6493368\charrsid1074055 \loch\af0\hich\af0\dbch\f13 \'a3\'ba}{\rtlch\fcs1 \af0 \ltrch\fcs0 \fs24\insrsid6493368\charrsid1074055 \par }\pard \ltrpar\qc \li0\ri0\sl180\slmult0\nowidctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid3869496 {\field{\*\fldinst {\rtlch\fcs1 \af0 \ltrch\fcs0 \fs24\insrsid1074055 \hich\af0\dbch\af13\loch\f0 \hich\af0\dbch\af13\loch\f0 HYPERLINK "http://www.downhi.com/"\hich\af0\dbch\af13\loch\f0 }{\rtlch\fcs1 \af0 \ltrch\fcs0 \fs24\insrsid13719882\charrsid1074055 {\*\datafield 00d0c9ea79f9bace118c8200aa004ba90b0200000003000000e0c9ea79f9bace118c8200aa004ba90b4600000068007400740070003a002f002f007700770077002e0064006f0077006e00680069002e0063006f006d002f000000795881f43b1d7f48af2c825dc485276300000000a5ab0000}}}{\fldrslt { \rtlch\fcs1 \af0 \ltrch\fcs0 \cs17\fs24\ul\cf2\insrsid3869496\charrsid1074055 \hich\af0\dbch\af13\loch\f0 http://www.downhi.com/txt/YBU77gDs3ChK.html}{\rtlch\fcs1 \af0 \ltrch\fcs0 \cs17\fs24\ul\cf2\insrsid6493368\charrsid1074055 \par }\pard \ltrpar\qj \li0\ri0\sl180\slmult0\nowidctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid6493368 }}\pard\plain \ltrpar\qj \li0\ri0\sl180\slmult0 \nowidctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid6493368 \rtlch\fcs1 \af0\afs24\alang1025 \ltrch\fcs0 \fs21\lang1033\langfe2052\kerning2\loch\af0\hich\af0\dbch\af13\cgrid\langnp1033\langfenp2052 \sectd \linex0\headery851\footery992\colsx425\endnhere\sectlinegrid312\sectspecifyl\sectrsid6493368\sftnbj {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid6493368\charrsid1074055 \par }{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid6493368\charrsid1074055 \par }\pard \ltrpar\qj \li0\ri0\sl360\slmult1\nowidctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid15866361 {\rtlch\fcs1 \af0 \ltrch\fcs0 \fs24\insrsid3869496\charrsid1074055 \hich\af0\dbch\af13\loch\f0 ----------------------------------------------- \par | File: keysdet.txt |\par | Author: Mod |\par | Email: fer2roc@excite.com |\par | Date: 10-30-99 |\par | Description: Tutorial on Keys Detection |\par | for QBasic and QuickBasic |\par | Level: Beginners and medium-level programmers |\par ----------------------------------------------- \par \par This document may be freely distributed provided that I am given credit,and\par that is unchanged (including this message).\par \par KEYS DETECTION (FROM THE BEGINNING)\par ===================================\par ------- \par | Intro |\par ------- \par One of the more important points in programming is how to identify the\par different keys, through which the user will interact with the program.\par Although many controlling actions (such as to open menus, to make scrolling,\par to input data, to quit, etc) may be accomplished with the mouse, the program\par must usually allow to make the same actions through the keyboard; also the\par data introduction (specially texts) is exclusively keyboard depending.\par In this tutorial we'll see how to identify the different keys in order to\par assign to them the functions we want, that's to say, how to represent the\par keys in our code.\par QBasic allows to use different ways to define the keyboard, each one has\par advantages and disadvantages. We'll review first 3 different methods and\par then we'll see how to choose one method depending on the characteristics of\par our program. The methods are not excluding and may be combined in the same\par program. Before analyzing each method, we must review some generalities\par about the keyboard and about the characters thas it represents.\par \par -------------- \par | The keyboard |\par -------------- \par Today it's almos http://www.downhi.com/txt/YBU77gDs3ChK.html t exclusively used the so called "extended keyboard", which\par has at least 103 keys. We'll see that some functions in QBasic are designed\par for older keyboards. Some keys are "controlling" keys, like Esc, Intro, Spc,\par arrow keys, etc. Other keys represent printable characters (most 2 but also\par 3). The keys pressing may be combined, we keep one key depressed and then we\par press another one. The Shifts, Ctrl and Alt keys make that and change the\par function of the second key. Other keys like CapsLock and NumLock act as\par "on/off" switches changing permanently the function of the other keys, until\par they are pressed again.\par It's important to say that keyboards vary in different countries. There are\par some different letters, punctuations marks and even the location of the more\par common letters may vary. This fact must be always considered by the\par programmer in order to code in a universal way, so that their programs may\par function well in any keyboard. There are keys that keep their position\par constant in different keyboards, other vary from country to country.\par \par ---------------- \par | The characters |\par ---------------- \par The ASCII code contains the 256 symbols that constitute the characters set.\par This number depends on the possibility of representing different data in a\par byte (in binary numbers, the 8 bits of a byte may go from 00000000 to\par 11111111, which is equivalent to decimal 255). Not all the ASCII characters\par are printable. Some represent actions, like beeping, carriage return, intro,\par etc. and each one has its own symbol, although it's neither is used in\par writing nor is drawn in the keyboard keys. The printable characters are the\par capital and lower-case letters, the numbers, the punctuation marks and a lot\par of symbols such as accented letters, foreign and old letters, and graphical\par figures that may be used for lay http://www.downhi.com/txt/YBU77gDs3ChK.html outing.\par Each character may be identified through its ASCII number, from 0 to 255.\par QBasic manages the ASC function, which returns the ASCII number for each\par specified character. The opposite function is CHR$, which returns the\par character for each ASCII number:\par \par PRINT ASC("a") The result will be 97\par PRINT CHR$(97) The result will be a\par \par The expression CHR$(number) is equivalent to the ASCII character that\par it represents.\par \par Is the same to say: IF a$ = "a" THEN..\par than to say: IF a$ = CHR$(97) THEN..\par \par Some function keys have a so called "extended code", which consist in 2\par ASCII characters and therefore it's stored in 2 bytes. The first one is\par always the null character CHR$(0), the second one is another character from\par the set. The extended code is represented as the addition of both\par characters. For example, the H letter has the ASCII code #72. But the Up\par arrow key has the extended code CHR$(0) "H" or CHR$(0) CHR$(72).\par Some keys (like Ctrl, Alt, Shift) haven't an ASCII number if they are\par pressed alone. They haven't an own function, they just modify the function\par of the others.\par As keyboards, the character set is not exactly the same in different\par countries, but letters, numbers and function symbols keep constant.\par Why the things must be complicated? Why not to use a single and complete\par code, which include the symbols used in all countries? It exists: UNICODE.\par But it needs to store each symbol in 2 bytes. That enhances the number from\par 256 to 65536, but it isn't practical. Usually we don't need more then 256\par symbols and we would be only duplicating the memory usage in order to have\par symbols which we would never use. As each language has its own necessities,\par it's more\par practical to introduce little variations in the character http://www.downhi.com/txt/YBU77gDs3ChK.html sets.\par \par --------------------- \par | International codes |\par --------------------- \par There are 24 different possibilities of keyboard and characters set\par varieties. he "keyb" command in DOS allows to know both the keyboard type\par and the haracter set that your system uses. In USA the "us" keyboard code\par and #437 character set are used. The complete keyboard codes and character\par sets list may be consulted in the DOS manuals.\par \par ---------------- \par | Keys detection |\par ---------------- \par Now we begin. The first thing that you have to know is, that there are 2\par ways of proceeding:\par \par (1) We may recognize the pressed "key", that's to say a key that has a\par determined location in the keyboard, independently of the function that t\par represent or the character that it contains. In order to do that, xist the\par so called "Keyboard Scan Codes".\par \par (2) We may recognize the entered "character", independently of the location\par of the key through which it entered. In this case, we use the ASCII code.\par \par It's important not to confuse them, because they aren't equivalent. For\par example the Esc key hat the scan code #1 and the ASCII code #27. If we put\par them in the wrong place the program won't function.\par \par In this tutorial we'll study 3 key detection methods:\par \par (1) The character detection through the INKEY$ function\par (2) The key detection through the ON KEY statement\par (3) The key detection through the INP function\par \par --------------------- \par | The INKEY$ function |\par --------------------- \par The INKEY$ function reads the keyboard buffer and it returns a string which\par consists just in the entered character. It may be compared with INPUT, but\par there are important differences. INPUT stops the program and waits that the\par user enter data. It only "knows" about the data when the user pr http://www.downhi.com/txt/YBU77gDs3ChK.html ess the\par Intro key and enters a string that may consist in several characters. INKEY$\par doesn't wait. It detects a single or extended character as soon as it was\par entered, without waiting for Intro. Also INPUT "makes echo", it prints the\par character on the screen and INKEY$ doesn't it. INKEY$ is excellent in a\par menu:\par you press the selected key and the action goes at once.\par \par a$ = INKEY$\par \par If we run this code, we'll see that the program just end. INKEY$ didn't wait\par for an input, it just returned a null character and the program continued.\par If we want that INKEY$ wait for a key pressing, we must code a loop like\par this:\par \par DO\par a$ = INKEY$\par LOOP UNTIL a$ <> ""\par \par Here we indicate that the program must keep the loop until the string cease\par to be a null string. This will occur when some key (with ASCII character)\par has been pressed. As we know the returned ASCII number we'll be able to know\par which key has been pressed, using IF or SELECT CASE structures and then we\par may assign to them the actions we want. Examples:\par \par CLS\par PRINT "In this program you may detect:\par PRINT "B - b - Intro - Up arrow - Down arrow"\par PRINT "Esc for ending"\par DO\par DO: a$ = INKEY$\par LOOP UNTIL a$ <> ""\par SELECT CASE a$\par CASE "B": PRINT "B key pressed"\par CASE CHR$(98): PRINT "b key pressed"\par CASE CHR$(13): PRINT "Intro pressed"\par CASE CHR$(0) "H": PRINT "Up arrow key pressed"\par CASE CHR$(0) CHR$(80): PRINT "Down arrow key pressed"\par CASE CHR$(27): END\par END SELECT\par LOOP\par \par The function a$ = INPUT$(1) is nearly equivalent to the INKEY$'s loop. http://www.downhi.com/txt/YBU77gDs3ChK.html It\par doesn't need Intro pressing and doesn't makes echo on the screen, but since\par it returns only one character you won't be able to differentiate the 2 bytes\par extended characters. Nevertheless, it's useful in the inespecific controlled\par pause "Press any key..", since it saves code.\par \par ---------------------- \par | The ON KEY statement |\par ---------------------- \par I used to hate ON KEY, because I used to find it capricious. Sometimes it\par seemed to work perfectly, sometimes not. Then I saw that the problem was the\par CapsLock and NumLock keys. I understood that, if one or both of them are\par activated, the function of all the keys is changed and the keys whose\par detection I programmed are not the same that those that the keyboard has\par now. Since I learnt how to solve it, I love ON KEY, I found it very useful.\par Its main advantage is, that I may put it at the beginning of a program (for\par example, to end if Esc is pressed) and I won't worry any more: the Esc key\par will be detected, although the program be running in a SUB or making a\par loop.It saves considerable code. Without ON KEY we should have to code the\par end\par condition in many parts of the program.\par \par ON KEY detects "keys", not characters. Therefore it uses the scan codes. But\par the syntax of ON KEY demands that these codes must be written inside of\par CHR$( ) functions and they will look like ASCII codes and this may be\par confusing. Also the ON KEY syntax requires to use a subroutine (memories of\par old basic). If we code ON KEY(15) PRINT "Hello", we'll get an "Gosub\par expected" error message. We must define a label and to set there the actions\par that we want and the returning instructions.\par \par The ON KEY programming has several steps:\par \par (1) Keys defining. Some keys are QBasic predefined. Others may be defined by\par the programmer using the KEY statement.\ http://www.downhi.com/txt/YBU77gDs3ChK.html par \par (2) For each key to detect we must set the ON KEY statement with the syntax\par ON KEY(n) GOSUB label.\par \par (3) Each key detection must be enabled using the KEY(n) ON (also may be\par disabled with the KEY(n) OFF statement, which it may be useful in some\par programs).\par \par (4) Coding of the subroutines, either one for each key or common, depending\par of our necessities.\par \par Do not confuse KEY, ON KEY(n) and KEY(n) ON, they are different statements.\par\par \par Only key defining may be somewhat complicated, and we'll see it in detail.\par The keys are identified through an order number, from 1 to 25 and 30 to 31\par (these are KEY statement's arbitrary numbers, they are neither scan codes\par nor ASCII codes). The Qbasic predefined keys are:\par \par 1 - 10 Function keys F1 to F10\par \par 11 - 14 Arrow keys (up, left, right, down). These arrow\par keys are those in the numerical keyboard keys\par (memories of the past again).\par \par 30 - 31 Function keys F11 and F12\par \par The keys from 15 to 25 may be defined by the programmer. Therefore we may\par define only 11 keys, and that it isn't too much, as we'll see. The syntax\par is:\par \par KEY number, CHR$(kbdFlag) CHR$(scanCode)\par \par The keyboardFlag indicates if the key that we're defining is combined with\par another one. We must use the following values:\par \par 0 if the key is pressed alone\par 1 to 3 if any Shift and the key are combined\par 4 if Ctrl and the key are combined\par 8 if Alt and the key are combined\par 32 if NumLock is activated\par 64 if CapsLock is activated\par 128 if we are defining some extended key\par \par Also these values may be combined each other. http://www.downhi.com/txt/YBU77gDs3ChK.html If we want to detect a\par Ctrl Alt key combination, the keyboardFlag must be 4 8 = 12.\par \par Other examples:\par - to detect the Intro key pressed alone: KEY 15, CHR$(0) CHR$(28)\par - to detect Ctrl Esc: KEY 16, CHR$(4) CHR$(1)\par - to detect the Alt key pressed alone: KEY 17, CHR$(0) CHR$(56)\par \par Notice that these codes look like extended ASCII codes, specially when the\par first term is CHR$(0). But I insist: the Alt key hasn't ASCII code. If we\par try to detect it with INKEY$ using\par CHR$(0) CHR$(56) or CHR$(0) "8", it on't work.\par \par Now we'll see a runnable example of Alt key detection:\par \par CLS\par KEY 15, CHR$(0) CHR$(56)\par ON KEY(15) GOSUB AltKey\par KEY(15) ON\par FOR n = 1 to 50000\par LOCATE 10, 36: PRINT n\par NEXT n\par END\par \par AltKey:\par LOCATE 12, 30: PRINT "Alt has been pressed"\par SLEEP 1\par CLS\par RETURN\par \par If this program didn't work for you, look at your NumLock and CapsLock. The\par Alt key may be detected, even if the program is running a loop, but it\par requires that both Locks to be inactivated. This is the reason: if one of\par both Locks are activated, the meaning of the other keys changes, we must\par consider them as combined. If we press now a key, we're really pressing a\par combination: NumLock key or CapsLock key or NumLock CapsLock key.\par NumLock Alt is not the same key than Alt. If we defined Alt, we had not to\par aspire that NumLock Alt can be detected. If we want to detect a key in any\par circumstance,\par we must define the key 4 times, covering all the possibilities:\par \par - to detect the Alt key pressed alone: KEY 15, CHR$(0) CHR$(56)\par http://www.downhi.com/txt/YBU77gDs3ChK.html - to detect it if Num Lock is on: KEY 16, CHR$(32) CHR$(56)\par - to detect it if Caps Lock is on: KEY 17, CHR$(64) CHR$(56)\par - to detect it if both Locks are on: KEY 18, CHR$(96) CHR$(56)\par (32 64 = 96)\par \par Then we may drive all GOSUBs to the same label:\par \par ON KEY(15) GOSUB AltKey\par ON KEY(16) GOSUB AltKey\par ON KEY(17) GOSUB AltKey\par ON KEY(18) GOSUB AltKey\par \par And, of course, all key detections must be enabled:\par \par KEY(15) ON: KEY(16) ON: KEY(17) ON: KEY(18) ON\par \par Now the program will detect the Alt key always. But notice that, since we\par may define only 11 keys, we'll be able to make a complete programming of\par only 2 keys. Fortunately, the Qbasic's predefined keys (F1 trough F12) work\par perfectly in all cases.\par \par Now an example of defining extended keys. We've seen above that the\par predefined arrow keys are those of the numerical keybord. The "normal" arrow\par keys belong to the extended keyboard and won't work as predefined keys. If\par we would want to detect them, we should define them as following:\par \par (Up arrow key: Scan code #72)\par - to detect it alone: KEY 15, CHR$(128) CHR$(72)\par - with Num Lock on: KEY 16, CHR$(160) CHR$(72)'(128 32 = 160)\par - with Caps Lock on: KEY 17, CHR$(192) CHR$(72)'(128 64 = 192)\par - with both Locks on: KEY 18, CHR$(224) CHR$(72)\par '(128 32 64 = 224)\par \par This is only an example of how to define extended keys. We couldn't define\par the extended arrow keys by this method, because we would need 4 * 4 = 16\par keys and we only dispose of 11. Indeed the "normal" arrow keys are detected\par well with INKEY$.\par \par ------------------ \par | The INP fu http://www.downhi.com/txt/YBU77gDs3ChK.html nction |\par ------------------ \par INP gets information through the I/O ports of the computer. If we give to it\par the hexadecimal &H60 address, we'll read through the keyboard I/O port and\par we'll get a value (one byte) that is the scan code of the last pressed key.\par Moreover, this value will be different if the key is still pressed or if it\par has been released:\par \par If the key is still pressed: we get the key's scan code\par if the key has been released: we get the key's scan code 128\par \par So, we may establish a key recognizing routine using the obtained value:\par \par CLS\par PRINT "In this program you may detect Ctrl y Alt"\par PRINT "Esc for ending"\par DO\par k = INP(&H60)\par LOCATE 12, 30\par SELECT CASE k\par CASE 1: END\par CASE 29: PRINT "The Ctrl key is pressed "\par CASE 56: PRINT "The Alt key is pressed "\par CASE 157: PRINT "The Ctrl key has been released"\par CASE 184: PRINT "The Alt key has been released "\par END SELECT\par LOOP\par \par Notice that we're detecting easily Ctrl and Alt, both keys haven't ASCII\par code and usually their detection is considered as difficult.\par Key detection with INP is very fast. Moreover the possibility of\par press/release detecting makes it very useful for games programming. As an\par example, we'll see how to transform the Intro key in a Accelerator:\par \par CLS\par PRINT "Press and release Intro"\par PRINT "Esc for ending"\par DO\par SOUND (50 incr), .5\par k = INP(&H60)\par SELECT CASE k\par CASE 1: END\par CASE 28\par http://www.downhi.com/txt/YBU77gDs3ChK.html inc = inc .5\par IF inc > 120 THEN inc = 120\par CASE 156\par inc = inc - .5\par IF inc < 0 THEN inc = 0\par END SELECT\par DEF SEG = &H40\par POKE &H1A, PEEK(&H1C)\par LOOP\par \par The 2 last lines inside the loop are a routine for discharging the\par keyboard buffer, avoiding saturation and beeping.\par \par --------------------------------------- \par | How to choose and combine the methods |\par --------------------------------------- \par Each method has their own advantages and disadvantages and therefore we\par couldn't say which is the best. We could say rather that a method will be\par the best in each specific case. You could have the following tips as a\par guide:\par \par (1) Use INKEY$ each time as you can. Detecting characters through INKEY$ is\par safer to get portability to our programs. If we ask the user for pressing\par the "A" key, our code will detect it, althought in some countries the "A"\par key may have another location in the keyboard. We have no limmits about how\par many keys to detect, but we only can detect the keys which have ASCII code.\par\par \par (2) Use ON KEY if you need keys that will be used along the whole program\par (for example Esc for end, F1 for Help). It may be useful also in games\par programming, if you need a repeating action along the whole program.\par Practically we count on the 12 predefined function keys (F1 through F12),\par since the numerical keyboard arrow keys are not to be used currently. If you\par can disable NumLocK and CapsLock, you should count on 11 keys to define, on\par the contrary only 2.\par \par (3) The keys which haven't ASCII code may be detected either through ON KEY\par or through INP, depending on their usage, frequent or ocasional, as it was\par st http://www.downhi.com/txt/YBU77gDs3ChK.html ated in (2). Althought you are using the scan codes, the position of the\par main controlling keys is quite constant and you won't have portability\par problems.\par \par (4) If you want speed and press/release detection, as in games, use INP\par \par Finally, here is an example about how the different method may be combined\par in the same program. In the example, Intro is detected through ON KEY, Ctrl\par through INP and Esc through INKEY$:\par \par CLS\par PRINT "In this program you may detect:\par PRINT " - Ctrl (through INP)\par PRINT " - Intro (through GOSUB)\par PRINT " - Esc (through INKEY$)\par KEY 15, CHR$(0) CHR$(28)\par KEY 16, CHR$(32) CHR$(28)\par KEY 17, CHR$(64) CHR$(28)\par KEY 18, CHR$(96) CHR$(28)\par ON KEY(15) GOSUB IntroKey\par ON KEY(16) GOSUB IntroKey\par ON KEY(17) GOSUB IntroKey\par ON KEY(18) GOSUB IntroKey\par KEY(15) ON: KEY(16) ON: KEY(17) ON: KEY(18) ON\par DO\par DO: a$ = INKEY$\par k = INP(&H60)\par IF k = 29 THEN\par LOCATE 10, 20: PRINT "Ctrl has been pressed"\par SLEEP 1\par LOCATE 10, 20: PRINT STRING$(21, 32)\par END IF\par LOOP UNTIL a$ <> ""\par IF a$ = CHR$(27) THEN\par LOCATE 10, 22: PRINT "Esc has been pressed"\par LOCATE 11, 20: PRINT "and the program will end"\par SLEEP 1\par END\par END IF\par LOOP\par \par IntroKey:\par LOCATE 10, 20: PRINT "Intro has been pressed"\p http://www.downhi.com/txt/YBU77gDs3ChK.html ar SLEEP 1\par LOCATE 10, 20: PRINT STRING$(22, 32)\par RETURN\par \par ----------------- \par | There is more.. |\par ----------------- \par The methods reviewed in this tutorial aren't all we can do. We could also\par detect keys looking in the memory through PEEK. We could make bit decoding\par to detect, for example, if the left or the right Alt key has been pressed.\par But this goes beyond the scope of this article.\par \par --------------------- \par | The tables you need |\par --------------------- \par In the Help File of QBasic 1.1 and QuickBasic 4.5 you'll find:\par \par - The ASCII Character Codes List\par \par - The Keyboard Scan Codes List\par \par - I'll give you the list of the more common extended ASCII codes\par (it lacks those of combined keys)\par \par Up arrow CHR$(0) "H" or CHR$(0) CHR$(72)\par Down arrow CHR$(0) "P" or CHR$(0) CHR$(80)\par Left arrow CHR$(0) "K" or CHR$(0) CHR$(75)\par Right arrow CHR$(0) "M" or CHR$(0) CHR$(77)\par F1 CHR$(0) ";" or CHR$(0) CHR$(59)\par F2 CHR$(0) "<" or CHR$(0) CHR$(60)\par F3 CHR$(0) "=" or CHR$(0) CHR$(61)\par F4 CHR$(0) ">" or CHR$(0) CHR$(62)\par F5 CHR$(0) "?" or CHR$(0) CHR$(63)\par F6 CHR$(0) "@" or CHR$(0) CHR$(64)\par F7 CHR$(0) "A" or CHR$(0) CHR$(65)\par F8 CHR$(0) "B" or CHR$(0) CHR$(66)\par F9 CHR$(0) "C" or CHR$(0) CHR$(67)\par F10 CHR$(0) "D" or CHR$(0) CHR$(68)\par F11 CHR$(0) "…" or CHR$(0) CHR$(133)\par F12 CHR$(0) "†" http://www.downhi.com/txt/YBU77gDs3ChK.html or CHR$(0) CHR$(134)\par Ins CHR$(0) "R" or CHR$(0) CHR$(82)\par Del CHR$(0) "S" or CHR$(0) CHR$(83)\par Home CHR$(0) "G" or CHR$(0) CHR$(71)\par End CHR$(0) "O" or CHR$(0) CHR$(79)\par PgUp CHR$(0) "I" or CHR$(0) CHR$(73)\par PgDn CHR$(0) "Q" or CHR$(0) CHR$(81)\par \par Try to make a program that gives the simple or extended ASCII code of any\par key or keys combination you press (if it has one).\par \par -------------- \par | Contact Info |\par -------------- \par That's all for this tutorial. Hopefully it will help newbies to clear\par their knowledge about key detection. If you have questions or comments\par you may contact me via email at:\par fer2roc@excite.com\par \par --------- \par | Credits |\par --------- \par I want to thank Zip, from whom I got some of the information of above.\par Also for reviewing the article and of course for hosting my tutorials\par on his web site:\par http://angelfire.com/co/zippy15\par }{ \rtlch\fcs1 \af0 \ltrch\fcs0 \fs24\insrsid6493368\charrsid1074055 \par }\pard \ltrpar\qj \li0\ri0\sl180\slmult0\nowidctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid6493368 {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid1074055 \par \par \par }{\rtlch\fcs1 \af0\afs30 \ltrch\fcs0 \fs30\cf17\dbch\af18\insrsid1074055\charrsid1074055 \hich\af0\dbch\af18\loch\f0 Free Document Search Engine. support all pdf,DOC,PPT,RTF,XLS,TXT\hich\af0\dbch\af18\loch\f0 ,Ebook! \hich\af0\dbch\af18\loch\f0 F \hich\af0\dbch\af18\loch\f0 ree\hich\af0\dbch\af18\loch\f0 \hich\af0\dbch\af18\loch\f0 download! You can search all kind of documents!}{\rtlch\fcs1 \af0\afs30 \ltrch\fcs0 \fs30\cf17\dbch\af18\insrsid6493368\charrsid1074055 \hich\af0\dbch\af18\loch\f0 }{ \rtlch\fcs1 \af0\afs30 \ltrch\fcs0 \fs30\cf17\insrsid1074055\charrsid1074055 \par }{\field\fldedit{\*\fldinst {\rtlch\fcs1 \af0\afs28 \ltrch\fcs0 \fs28\cf11\insrsid14892288\charrsid1074055 \hich\af0\dbch\af13\loch\f0 HYPERLINK "http://www.downhi.com/"}{\rtlch\fcs1 \af0\afs28 \ltrch\fcs0 \fs28\cf11\insrsid10707375\charrsid1074055 {\*\datafield 00d0c9ea79f9bace118c8200aa004ba90b0200000003000000e0c9ea79f9bace118c8200aa004ba90b4e00000068007400740070003a002f002f00770065006e00640061006e0067002e0064006f00630073006f0075002e0063006f006d002f000000795881f43b1d7f48af2c825dc485276300000000a5ab0000000000}} }{\fldrslt {\rtlch\fcs1 \af0\afs28 \ltrch\fcs0 \cs17\fs28\ul\cf2\insrsid14892288\charrsid1074055 \hich\af0\dbch\af13\loch\f0 http://www.downhi.com/}}}\sectd \linex0\headery851\footery992\colsx425\endnhere\sectlinegrid312\sectspecifyl\sectrsid6493368\sftnbj {\rtlch\fcs1 \af0\afs28 \ltrch\fcs0 \fs28\cf11\insrsid6493368\charrsid1074055 \par }{\rtlch\fcs1 \af0\afs28 \ltrch\fcs0 \fs28\cf11\insrsid15098623\charrsid1074055 \par }}