Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-03-2014, 12:38 AM
100Zero100 100Zero100 is offline
Registered User
Join Date: Jul 2006
Posts: 31
100Zero100 is on a distinguished road
keyName2()?

Seems broken.

keyName2(getKeycode("a")) should retrieve "a" and instead retrieves "A"

y it do dis?

Is there another method to retrieve a key name from its key code, without making my own array and doing it that way?
__________________
Hi. I'm NaS!
Reply With Quote
  #2  
Old 02-03-2014, 12:18 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by 100Zero100 View Post
Seems broken.

keyName2(getKeycode("a")) should retrieve "a" and instead retrieves "A"

y it do dis?

Is there another method to retrieve a key name from its key code, without making my own array and doing it that way?
Wait, capital letters, and lowercase letters have seperate keycodes aside from the fact you have to press shift, to achieve the capital letter??

I did the following,

PHP Code:
getKeycode("a"); // result = 65
getKeycode("A"// result = 65
keyName2("45"); //result = "insert" 
As you can see it's not doing capital and lowercase it's doing which phisical button... what is it exactly you are trying to do maybe we can help guide you in another direction to accomplish this? Because it's already displaying which of the ~ 101-105 keys on the keyboard you pressed. To check if it's capital you need to know if the shift key was pressed or the cap lock was activated at the time of recording the key being pressed.
Reply With Quote
  #3  
Old 02-03-2014, 10:20 PM
100Zero100 100Zero100 is offline
Registered User
Join Date: Jul 2006
Posts: 31
100Zero100 is on a distinguished road
Quote:
Originally Posted by scriptless View Post
Wait, capital letters, and lowercase letters have seperate keycodes aside from the fact you have to press shift, to achieve the capital letter??

I did the following,

PHP Code:
getKeycode("a"); // result = 65
getKeycode("A"// result = 65
keyName2("45"); //result = "insert" 
As you can see it's not doing capital and lowercase it's doing which phisical button... what is it exactly you are trying to do maybe we can help guide you in another direction to accomplish this? Because it's already displaying which of the ~ 101-105 keys on the keyboard you pressed. To check if it's capital you need to know if the shift key was pressed or the cap lock was activated at the time of recording the key being pressed.
Retrieving "keycode" from:

function keyPressed(keycode, key, scancode) {
}

keycodes for lowercase letters and uppercase letters are off by 256. ie, if 'a' is 65, 'A' is 65 + 256. This is also true of 1 to ! and other symbols. Sure, I suppose with the proper tools you can probably BUILD the final keycode (set a var if shift is down or capslock is on, add 256 to the getkeycode if var is true, etc). But that's dumb -- why are the onKeyPressed and getKeycode/keyName2 functions NOT directly compatible with each other?

That said, typing "!" yields a keycode of whatever 1's keycode is plus 256.

However, doing getKeyCode("!") yields 0. It doesn't even yield the keycode for 1. So even if I'm supposed to "build" the keycode out of knowledge as to whether shift or capslock is on (not that there's any support for that...), I still couldn't build the value for ! unless I access the value for 1 and add 256. I couldn't unbuild it unless I accessed its original value (as opposed to just doing - 256).

Say for example one wanted to make an on-screen keyboard. Let's assume that person only wanted to use 1 array, an array of keycodes. What would be nice is something like:

keys = {"`", "1", "2"}; // define the keys of a QWERTY keyboard in order
Then loop keys, performing getKeycode(key) to build a 2nd array of the keycodes.
Then loop keys, performing getScancode(key) to build a 2nd array of scancodes (if needed/as needed)

Can't do that, because getKeycode(key) does not work for any shifted keys. Yes you could store what the base key is and for a shifted key you could add +256, but then the whole method is wash.

So instead you try:

keycodes = {num0, num1, num2, ...}; // array of the keycodes, in order of QWERTY

Okay, so now it's time to build your array. Except keyName2() does not return a different value between lowercase, uppercase, and returns null for a lot of symbols.

Okay, so the final method (arguably best method) is to use Scancode: scancodes start at 2 for 1, 3 for 2, etc. Nice thing is that they increase linearly, where 11 is 0, 13 is =, 14 is backspace, 15 is tab, 16 is q, etc. Looks like they're actually made for keyboards. You could probably just loop the scancodes to establish the bulk of a base keyboard, and then add the sides/top frills afterwards. You wouldn't even need a QWERTY array.

But there's no function to determine the scancode of a letter, and no function to determine the letter from a scancode.

getASCII()/char() is also a bust whenever any invisible symbol comes up.

So ultimately, the only method that would work by my estimation, is:
1. a big ass array of QWERTY letters
2. a second array of their shifted letters (because keyName2(keyCode(1) + 256) DOES NOT yield "!")
3. a corresponding array of keycodes (because getKeyCode("!") would yield null)
4. POSSIBLY ALSO an array of scancodes (such a scancode array COULD prove useful; the 2 shift's have the same keycode but different scancode, and all SPACEBAR ENTER, TAB, etc entries have the same scancode, while there are like 15 diff keycodes for them (depending on which mod keys are held down), so you'd have to do an "in" {} check if you wanted to determine them by keycode).

So that's like 4 arrays each having like 50 entries. I'm sure it works, but it looks lame. 1 array of qwerty letters that you could derive keycodes from (or visa-versa) + the ability to use math to shift a letter on-demand would make the whole thing nicer.

Unless you've got some other idea for an approach I haven't thought of?
__________________
Hi. I'm NaS!
Reply With Quote
  #4  
Old 02-03-2014, 11:04 PM
Tim_Rocks Tim_Rocks is offline
a true gentlemen
Tim_Rocks's Avatar
Join Date: Aug 2008
Location: USA
Posts: 1,863
Tim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to behold
Why not just do this?
PHP Code:
function keyPressed(keycodekeyscancode) {
  
player.chat keycode ", " key ", " scancode;

__________________
Reply With Quote
  #5  
Old 02-05-2014, 10:51 AM
100Zero100 100Zero100 is offline
Registered User
Join Date: Jul 2006
Posts: 31
100Zero100 is on a distinguished road
Quote:
Originally Posted by Tim_Rocks View Post
Why not just do this?
PHP Code:
function keyPressed(keycodekeyscancode) {
  
player.chat keycode ", " key ", " scancode;

In my proposed scenario, I'd want to build a full QWERTY keyboard on-screen WITHOUT the need for the player to press down all of the keys on their keyboard.

If you read my second post, I specifically complained that the keycode/key translation obtained from onKeyPressed() is not compatible with the keycode/key translation of getKeyCode()/keyName2()
__________________
Hi. I'm NaS!
Reply With Quote
  #6  
Old 02-07-2014, 02:09 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Take a look at this:

PHP Code:
//#CLIENTSIDE
function onkeyPressed(keycodekeyscancode) {
  
player.chat "keyname2" SPC keyName2(keycodeSPC "keycode:" SPC keycode SPC "key:" SPC key SPC "scancode:" SPC scancode;

Here are results:

PHP Code:
Pressing "a" ===================== "keyname2 A keycode: 65 key: a scancode: 0"
Pressing "a" plus "left shift" === "keyname2 A keycode: 321 key: A scancode: 0"
Pressing "left shift" ============ "keyname2 Left Shift keycode: 160 key:  scancode: 56" 
What it looks like it is doing is showing you which key is pressed, not the ascii or hex value of the character you are typing. It also looks like keycode will equal 256 + hex value of character if shift is pressed.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:06 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.