![]() |
onKeyDown, onKeyUp
I'm trying to learn how to do GUI stuff, but I haven't been able to master the onKeyDown and onKeyUp events... can someone gimme a working example or explain wtf a scancode and all that stuff is?
Quote:
to ApothiX -> outstanding edit, sir! |
http://en.wikipedia.org/wiki/Scancode
http://en.wikipedia.org/wiki/Scancode Edit: Received a PM from the maker of the thread requesting more information, and not just a link with "someone else's words" on it. A simple method of determining what key has what scancode can be scripted. This script does just that (In old-gscript for compatibility with the editor, it's not likely that you'd want to upload something like this to a server.) PHP Code:
PHP Code:
PHP Code:
Quote:
Edit again: <_< Now that I re-read it, keycode and scancode may be mixed up in those examples. I haven't done this for awhile so you may want to double check that. Scancode can still be determined using a method similiar to this, although all scancodes are shown on the wiki page I linked to. |
In v4 the old scripting engine is providing the scancode too.
Keycode - the virtual keycode, you can search for VK_ESCAPE (or XK_) or similar on the web. That works also for special keys, like Escape, Shift etc. You can get the keycode for a special character with the function getkeycode(character). Also the function keydown2(keycode,ignoremodifierkeys) requires keycodes. Keystring - the character pressed, e.g. 'a' Scancode - the number of the key on the keyboard. This is different on Mac (USB keyboards?) and Windows/Linux, but it's the only way to detect some keys that are used for several characters at the same time. This has been added in v4 to make things like Piano simplier. You need to test this on Mac though since the scancodes are different there (check player.platform). Best might be in this case to let the player choose the keys he/she wants to use, although that will require some scripting to ask the player to press the wanted key and then check in onKeyDown what scancode the key has. |
onKeyDown() and onKeyUp() are basically the same as onKeyPressed() but instead works if you press a key while the control you use it with has focus (of course onKeyUp() is the same as onKeyDown() but is triggered when you release the key). The keycode is basically the number assignment for the key you press down.
An easy way to check for the keycode in an online script: NPC Code: This of course will show you the keycode, key letter and scancode in question being pressed. Keystring is just the label of the key that you press but it doesn't always work (It only works for character keys such as letters, numbers and other charcters like : [ , . ' / ~). It will just be blank for keys such as shift or page down. Scancode I haven't really worked with much. Can't help you with that sorry. |
Quote:
Just incase they aren't, here is a snippit from WinUser.h (C Header file that ships with win32-comptible compilers) PHP Code:
|
And seeing as how I have nothing else better to do, I took the liberty of converting that header file into an enum supported by gscript2.
PHP Code:
|
I think that the virtual keycodes come from Unix, e.g. XK_Escape is 0xff1b, the VK_ codes are introduced by Windows but are basicly the same (VK_ESCAPE=0x1b)
|
Quote:
|
I said they are the same when you just take the last two hexadecimal characters :)
|
GScript Mid-Term Exam:
Instructions. /* Indicate validity of example GScript code in a boolean value expression of "this.answer", where this.answer is equal to the example GScript given. if (this.answer==false) { explain("why"); } */ 1) PHP Code:
Really though — can someone give me a working example? I read the posts and I see hexadecimals and header files.... I learn things by dumbing them down via example, and hexadecimal definitions aren't exactly my idea of dumb. |
the enum crap I provided lets you do things like this:
PHP Code:
|
| All times are GMT +2. The time now is 01:33 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.