![]() |
GrowlZ's Tutorial #1: The Keyboard
1 Attachment(s)
Yes, Graal now has full keyboard detection. Neat, huh? For those of you who want to use this handy new feature, but don't know quite how yet, here's your opportunity to learn.
To understand this properly, you need to understand that the keyboard has two basic types of key: character keys and operation keys. Character keys are buttons that produce a symbol or letter when pressed, for example the "S" or "5" keys. Operation keys are keys that cause the computer to do a special function, for example: "Caps Lock", "Tab" (which sometimes prints a space, but which Graal views as an operation key), "Return" and all the cursor keys (Up, Down, Left and Right). Graal's "keypressed" keyboard detection can only handle character keys. With that cleared up, let's begin. There's one new event, keypressed. This is for detecting when a character key is pressed. So: NPC Code: ... will cause a NPC to show itself when a character key is pressed. Simple enough. But how, you may ask, do you find out which key has actually been pressed? Here's when we find out about the two new messagecodes, #p(0) and #p(1). NOTE: Yes, I know #p messagecodes were formerly used for triggeraction parameters. In fact, they still are. #p(2) will still give you a triggeraction param, rather than a key name. But #p(0) and #p(1), for all practical purposes, are now keyboard messagecodes. I haven't been able to test what happens if a NPC that has an action triggered on it checks #p(0) (will it return a triggeraction parameter, or a keycode?) because triggeraction always sucks and refuses to work for me. If anyone can find out the result, I'd appreciate it. And now, back to the tutorial. #p(0) returns the KEYCODE of the character. A keycode is a number assigned to a character to distinguish it from the others: for example, the character "p" has the keycode 80, whereas the character "s" has the keycode of 83. IMPORTANT! Keycodes differ between case. A small letter "p" won't return the same keycode as the capital "P". #p(1) returns the actual NAME of the character. For example, the name of the character "p" is, surprisingly enough, "p". "q" has the name "q", "f" is "f", and "@" comes out as "@". The character's name is basically just the character itself. Small thing to consider here: Graal doesn't seem to be able to recognize the name of the "," character. So try and leave that out of your #p(1) scripts. So to test if the key "p" has been pressed using #p(0), it would be: NPC Code: To do the same with #p(1): NPC Code: Keyboard detection has also added two new functions, keycode(character) and keydown2(keycode,ignorecase<false/true>). Keycode(character) lets you check the keycode of any character you want. You can use this to bypass #p(0) altogether, using keycode(#p(1)), but why would you want to do that? :P Keydown2(keycode,ignorecase<false/true>) is a little more complicated. This function actually uses the other function, keycode(character), to find out the button you want to press. Now, as I've told you earlier, case matters when we're talkin' about keycodes... or at least, it does without the help of keydown2. The ignorecase part has two states: "true" or "false". If ignorecase is "true", then no matter whether the key is a or A, p or P, f or F, it will always be treated as the same letter. Here's an example of how you would use keydown2. NPC Code: In case you're wondering, it's in a timeout loop because functions have to be checked by something else. They can't do themselves when something happens. This ends my keyboard tutorial: anything you need clarified, comments, suggestions, complaints, etc., just post 'em here. Or say what you thought with the poll. I'm listening! The attatchment below is a Graalscript to help you check keycodes for characters. It requires Graal v.2.14 or later to work properly. |
ooo good job
|
Nice job
Excellent work.
|
They should sticky this tutorial.. in fact they need to sticky all tutorials :o
|
Great Job :)
|
Keycodes are a dirivitive of the ascii indexes of the characters. So if you have an ascii conversion chart (or memorized it) it would help to some extent (knowing that space is 32 and so on) ;)
It works something like 0x<special><index> so if you press shift... a, you would have 0x141 or 16^2 *1 + 16^1 *4 + 16^0 *1 which is 321 I use 41 as the index becasue the hexidecimal value for 65 (keycode for a) is 41 (this is why an ascii chart is sometimes needed, its hard to explain how hexidecimal values work, its base 16 so figure it out) the special case would be if shift or ctrl were true. (im guessing, since this is what it seems to do) special = 1 would be shift speical = 2 would be ctrl so control + a would be 0x241 or 16^2 *2 + 16^1 *4 + 16^0 *1 which is 577 |
Good job.
I'm a little lazy, but I know if you open up visual basic you'll find the numbers for all the buttons in there. |
I love you for this.
Marry me? |
| All times are GMT +2. The time now is 01:14 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.