Normal Topic @GetFromKeyboard() (Read 1301 times)
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
@GetFromKeyboard()
Mar 23rd, 2005 at 1:54am
Print Post Print Post  
Could use some explanation here, please.

It appears that @GetFromKeyboard() only works in Text elements.  And @GetFromKeyboard() only traps alpha-numberic keys, does not capture any function keys.  Trying to use Up/Down arrows for example do not seem to get trapped, probably because they have no ascii value.

I wanted to trigger actions by entering  "?" in a field, and it only works in Text.  Entering into Number, Money, Date, Time elements generates an error about wrong type or just passes the character along.

And even in the Text element, the "?" is passed on to the element (with and without using GiveToKeyboard).  This was a simple sample test to add a string to the existing value: 
Code
Select All
// ASCII 53 is the "?" character

var vTemp as int

vTemp = 0
vTemp = @GetFromKeyboard()
if(vTemp = @Asc("?")) {
	TestText = TestText + "abc"
	TestText = @Replace(TestText,"?","") //Need to remove "?" character
	}
GiveToKeyboard()     //Made no difference when commented out
 



I was expecting @GetFromKeyboard would eliminate the keystroke from being passed along until GiveToKeyboard() was generated.  I had to use @Replace to remove the "?" that I thought would be stripped out.

It is obvious to me that I do not yet understand how these are intended to function.

Some questions:
1.  Why does @GetFromKeyboard still get passed on to the element?
2.  What does GiveToKeyboard do?
3.  When should it be used? I am putting test code in event for ImmediateChange.
4.  If I am correct that theses functions only work with Text Fields, could it please be changed in the future to also work in Numbers/Money/Date/Time fields?
5.  Could it also be expanded to trap the keyvalue from the keyboard vs. using the ascii value?
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: @GetFromKeyboard()
Reply #1 - Mar 23rd, 2005 at 3:49pm
Print Post Print Post  
Quote:
t appears that @GetFromKeyboard() only works in Text elements.  And @GetFromKeyboard() only traps alpha-numberic keys, does not capture any function keys.  Trying to use Up/Down arrows for example do not seem to get trapped, probably because they have no ascii value.

It does not need to be from a text element. I just used it On Form Enter without problem. It can be used from any element on a form in any event after the form has been opened. It traps events from the main Sesame window - not any particular element in that window.
It also traps all keys, not just those with ASCII equivalents - that is why it returns an integer rather than a byte. The value of the Up Arrow key on most keyboards will be 65362. You must use integers unconverted to characters to use this function.
Quote:
I wanted to trigger actions by entering  "?" in a field, and it only works in Text.  Entering into Number, Money, Date, Time elements generates an error about wrong type or just passes the character along.

And even in the Text element, the "?" is passed on to the element (with and without using GiveToKeyboard).  This was a simple sample test to add a string to the existing value:   

What are you using to trigger the event to run in the first place? If, for example you are using on LE enter - then your code will run once, complete and not run again until the LE is re-entered. That will produce exactly the symptom you are noting. If you put it in LE immediate change, it will only run after the first keystroke has changed the LE, then it will run once, and without a loop - stop, until the next change.
Quote:
I was expecting @GetFromKeyboard would eliminate the keystroke from being passed along until GiveToKeyboard() was generated.  I had to use @Replace to remove the "?" that I thought would be stripped out.

It needs to be put in a loop to act as a filter.
Quote:
Some questions:
1.  Why does @GetFromKeyboard still get passed on to the element?
2.  What does GiveToKeyboard do? 
3.  When should it be used? I am putting test code in event for ImmediateChange.
4.  If I am correct that theses functions only work with Text Fields, could it please be changed in the future to also work in Numbers/Money/Date/Time fields?
5.  Could it also be expanded to trap the keyvalue from the keyboard vs. using the ascii value?

1. It doesn't. If placed in LE enter, it will trap (and dispose of) the first keystroke entered. To prevent further keys from being placed in the LE, a loop is required.
2. It puts the last trapped keystroke back in the event queue.
3. It pretty much cannot be used in immediate change in that it will not run until the user does hit a key and changes the LE. Instead put it in LE enter, or Form enter, and use a loop with an exit condition.
4. It will work in any LE type that has programmable events.
5. It traps all keystrokes and they are returned as integers. This can be demonstrated by placing the following in the On Enter event of any LE:
Code
Select All
var aa as int
var cnt as int

cnt = 0
while(cnt < 10)
{
  aa = @GetFromKeyboard()
  writeln(aa)
  cnt = cnt + 1
}
 


  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: @GetFromKeyboard()
Reply #2 - Mar 23rd, 2005 at 8:09pm
Print Post Print Post  
Thanks for the info Mark. V

I just did a quick read through and you confimed my suspicion that I did not understand it.  Now with this extra information, I think I will probably be able to use it the way I hoped. 

WARNING- I hope to be experimenting with this over the next few days, expect more questions. Shocked
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: @GetFromKeyboard()
Reply #3 - Mar 25th, 2005 at 3:53am
Print Post Print Post  
While working on GetFromKeyboard(), I thought it would be useful to know what the actual keycodes were.  So here is a listing that I made of MY KEYBOARD.  Your results will probably differ slightly for Windows OS, greatly for Linux.
Code
Select All
Keycodes for 101 Windows Keyboard on WIN98SE system.
Different keyboards, OS may produce different results.
===========================================================

------- Main Keyboard Control Keys ---------------
    65505 LeftShift     65505 RightShift
    65507 LeftControl   65508 RightControl
    65513 LeftAlt		 65514 RightAlt
    65511 LeftWindow	   65512 RightWindow
    65383 Menu
    65289 TAB	    65288 Backspace
    65509 CapsLock	65293 ENTER
    65307 ESC

------- Upper central keypad keys ---------------
    65379   Insert	65535 Delete
    65360   Home	  65367 End
    65365   PageUp	65366 PageDown

-------- Numeric keypad keys (on right)--------------
    65407 NumLock   47 KP /   42 KP *   45 KP -
    55 KP 7	    56 KP 8   57 KP 9   43 KP +
    52 KP 4	    53 KP 5   54 KP 6
    49 KP 1	    50 KP 2   51 KP 3
    48 KP 0	    46 KP .	    65293 Enter

--------- Arrow keys -----------------------------
    65362 UP
    65361 LEFT			65363 RIGHT
    65364 DOWN

---------- Function keys F1-F12 ------------------
    blank F1		65471 F2
    65472 F3		65473 F4
    65474 F5		65475 F6
    65476 F7		65477 F8
    65478 F9		65479 F10
    65480 F11  65481 F12

----------- Additional 3 keys on  keyboard (Top right)-------
    blank PrintScreen
    65300 Scroll Lock
    blank Pause/Break

============= SAME AS ASCII VALUES ==================
------Main Central Keyboard Alpha-Numeric ----------
LowerCase	UpperCase
a-z = 97-122	A-Z = 65-90 (lowercase + 32)
~ = 126		` = 96
- = 45		_ = 95
= = 61		+ = 43
\ = 92		| = 124
/ = 47		? = 63
; = 59		: = 58
' = 39		" = 34
, = 44		< = 60
. = 46		> = 62
0 = 48		) = 41
1 = 49		! = 33
2 = 50		@ = 64
3 = 51		# = 35
4 = 52		$ = 36
5 = 53		% = 37
6 = 54		^ = 94
7 = 55		& = 38
8 = 56		* = 42
9 = 57		( = 40
Space = 32
--------------------------------------------------------
Exception notes:
Missing some codes above 31: 91, 93, 123, 125, 127+
Is F1 = 65470 ?
PrintScrn and Pause returned no value I could see.
NumLock Off side keypad keys give same value as main keyboard. 


Newer keyboards/laptops have more keys for other functions like sound, monitors, snooze, etc.  This is not an intent to cover all keyboards.  This was intended for the keyboard I have attached to a 4-way KVM on Windows systems.  But I thought you could use this as a beginning template to record your own keyboard if you wanted.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged