# Exploring KSP in K2.1 - letting the user enter strings



## kotori (May 7, 2006)

I figured since there isn't any text edit control we will just have to make it ourselves. Here's my take at giving the user a possibility to input text. This can be useful, eg. for naming presets. Pressing C3 enters the first character, C#3 enters the second and so on. It's easy to expand this example to provide the user with a way to delete characters and move forward and backward in the string. To do that one would have to store the individual characters in the text in an array of strings (each representing a letter) and then concatenate these ever time there is a change.

``*on init*``
````_{ list of all letters }_
````*declare* !letters[27]
````letters[00] := " "
````letters[01] := "a"
````letters[02] := "b"
````letters[03] := "c"
````letters[04] := "d"
````letters[05] := "e"
````letters[06] := "f"
````letters[07] := "g"
````letters[08] := "h"
````letters[09] := "i"
````letters[10] := "j"
````letters[11] := "k"
````letters[12] := "l"
````letters[13] := "m"
````letters[14] := "n"
````letters[15] := "o"
````letters[16] := "p"
````letters[17] := "q"
````letters[18] := "r"
````letters[19] := "s"
````letters[20] := "t"
````letters[21] := "u"
````letters[22] := "v"
````letters[23] := "w"
````letters[24] := "x"
````letters[25] := "y"
````letters[26] := "z"``
``````
````*declare* ui_label label(1,1)```
````*declare* @text```
````make_persistent(text)
````_read_persistent_var(text)
````set_text(label, text)
``*end on*
``
``*on note*
````*if* in_range(EVENT_NOTE-60, 0, 26)
``````_{ add the letter determined by the note to the string }_
``````text := text & letters[EVENT_NOTE-60]
``````set_text(label, text)
````*end if*
``*end on*


Cheers,
Nils


----------



## Thonex (May 7, 2006)

I think NI should be paying you for some of your cool ideas!!

Actually, I think Frederick should post a sticky where we can store "modules" of code (for lack of a better word) that we contribute to the forum. This way we could, for example, have a little data base that deals with very useful functions that people can use (like this one above) or Note naming modules etc. Also it could be as "code" on the BBS so that we could copy/paste it to our scripts with not weird formatting issues.

Nils, do you think this could be useful??

Cheers,

T


----------



## kotori (May 7, 2006)

Hi Andrew,
thanks for the supporting words. Maybe the best thing would be to have a single web page or forum thread that _linked_ to individual threads. I think that would be useful.
The above code is fairly easy to copy and paste. You just have to search and replace Â´ with space.

Regarding entering text, maybe an even nicer solution than using the keyboard (like I suggested above) would be to have buttons with three characters each and then entering text like you do on cellphones. These controls could be placed on a separate "tab".

Cheers,
Nils


----------



## Thonex (May 7, 2006)

kotori @ Sun May 07 said:


> Regarding entering text, maybe an even nicer solution than using the keyboard (like I suggested above) would be to have buttons with three characters each and then entering text like you do on cellphones. These controls could be placed on a separate "tab".
> 
> Cheers,
> Nils



Since we have 6x6 matrix in which to have buttons, we could probably have room for buttons of all 26 letters of the alphabet and back-space (delete) , forward-space and a text display area along with the toggle "tab" switch (or something like that)..... no? I think there would even be room left for number 0-9 with a three additional buttons (like cell phone)... no?


T


----------



## kotori (May 7, 2006)

Thonex @ Sun May 07 said:


> Since we have 6x6 matrix in which to have buttons, we could probably have room for buttons of all 26 letters of the alphabet and back-space (delete) , forward-space and a text display area along with the toggle "tab" switch (or something like that)..... no? I think there would even be room left for number 0-9 with a three additional buttons (like cell phone)... no?


Yes, you're absolutely right. I guess I got a bit "klaustrofobic" using the limited area in K2.0 so I must have underestimated the size. :wink:


----------



## Thonex (May 7, 2006)

kotori @ Sun May 07 said:


> Thonex @ Sun May 07 said:
> 
> 
> > Since we have 6x6 matrix in which to have buttons, we could probably have room for buttons of all 26 letters of the alphabet and back-space (delete) , forward-space and a text display area along with the toggle "tab" switch (or something like that)..... no? I think there would even be room left for number 0-9 with a three additional buttons (like cell phone)... no?
> ...



Actually, we could even have a "shift" button to allow upper-case and lower-case letters and characters along with the numbers :wink: 

Now.... I expect this to be done in 19 minutes :wink: :lol: 

Just kidding of course..... 20 minutes would be fine :shock: again... just kidding... just thinking out load here.

Cheers,

T


----------



## Big Bob (May 7, 2006)

Are one of you guys going to do this, or should I? What we should do is to implement this as a User Function that can be put in any of our scripts that might require text input. Of course this whole thing should be hidden until you need to enter text and then go away again when you are done.

I know I'm going to need this function for the next version of SIPS but,
instead of each of us running off and doing this on our own, why don't we save the duplication of effort. Nils, since you suggested the idea, why don't you act as the project engineer and delegate whatever parts you'd like others to do. Maybe we should first have a brainstorm session to make sure we will design the most useful function.

What do you think guys?

Bob

BTW After we all agree how the thing should work, I'll be glad to implement any or all of it.


----------



## Thonex (May 7, 2006)

Big Bob @ Sun May 07 said:


> instead of each of us running off and doing this on our own, why don't we save the duplication of effort. Nils, since you suggested the idea, why don't you act as the project engineer and delegate whatever parts you'd like others to do. Maybe we should first have a brainstorm session to make sure we will design the most useful function.
> 
> What do you think guys?



I think that's a great idea!!!!

In fact, that is sort of why the new "sticky" is (at the top of the K2 forum).... so we can devolpe "modules" (for lack of a better word) like this and incorporate them into our own scripts.

Cheers,

T


----------



## Big Bob (May 7, 2006)

Here's some preliminary input for the brainstorm session. Since this 'Kiddie Typewriter' we're going to concoct will probably use a fair amount of code and address space, and since NL User Functions are really 'in-line' macros, we may want to resurrect my pre-NL Editor scheme for doing psuedo subroutine calls. Then we can call the 'Get_Text' function from multiple places in our scripts without having to generate so much actual K2-Ready code.

The scheme basically consists of dedicating a MIDI note (like note 0) and using it as part of a special 'calling sequence'. This calling sequence itself can be nicely implemented as a User Function. I think I used this general idea with the PCE in the pre NL days. If you want I'll concoct something for this part of the project.

Keep the Faith,

Bob

BTW Isn't it a shame that we have to cook up a 'Kiddie Typewriter' when all NI had to do was to give us one more UI control like the one used to enter script names :cry: .

Oh and Nils, here's another suggestion, why don't we make the Get_Text function use two arguments, a text variable and an integer. Both these parms can be input/output. The integer can be used for Mode control on input and as a return Status code on output. That way the user can optionally input a default string that will be displayed for editing if desired and the Status code can tell the caller if the operation was successful or not, etc.


----------



## Big Bob (May 7, 2006)

Whoops!

Until a little while ago, I hadn't actually tried to use any of the new string vars and arrays. I hope I'm wrong but there are several limitations that are just about going to put the kabash on naming User Presets in SIPS.

1. The add_menu_item cannot be used in any callback except on init.

2. String arrays cannot be made persistent.

3. Menu items cannot be renamed with set_text

So, if I were to use our 'Kiddie Typewriter' to allow the user to name a preset, the only way to get it into the menu would be to save the name to a persistent string variable, and then have the user hit the Apply button! This would have to be done after each name entry. Hoaky, Pokey, a penny a lump!

I guess another way to do this might be to make our own Menu control with a series of buttons that 'pop up' (instead of the usual menu drop-down list). Since buttons can be renamed in all callbacks, this would probably work. But, it sure seems like doing it the hard way, no?

Now we need to hound NI for two things: a text input control and the ability to call add_menu_text from any callback.

Bob


----------



## Thonex (May 8, 2006)

Wow Nils!!!!  

You never cease to amaze me!!!! That looks great and the "show cursor" button is amazing.... I would never even have thought of that.

let me know if you want me to post these links on the sticky or if you are going to do some more work on it.... in that case I'll wait.

This is really great.... such an elegant solution.

Cheers,

T


----------



## Big Bob (May 8, 2006)

Hey Beautiful job Nils, the flashing cursor idea is brilliant!

Andrew, why not wait a little on posting it as a module until we all get a chance to play with it and kick it around a little. For example, I'd like to add digits and characters and discuss alternate ways of character entry so that our standard module for this might be able to offer several different ways of entry, etc. I'd also like to suggest that we discuss a standardized calling sequence (as I mentioned previously) to reduce some of the 'bloat' if we want to call this thing from more than one place in a script. I'm not trying to 'steal your thunder' here Nils, but if we want to make this a 'standard module', maybe we should agonize over it a little first?

I want to take a more detailed look at your code but first I need to run off to a dental appointment:cry: . Hopefully, I'll be back before this is all changed and cast in concrete :wink: .

Bob

PS Hey Nils, I just had a wild thought on my way out the door to the dentist (I guess because I'll do anything to delay that :wink: ), since we can read text from Group names, maybe you could think of some clever way to utilize that for text entry. For example, have the script always get the text from the last group. The user could fairly easily create an extra empty group for this purpose. It's not as fully under control of the script as we'd like, but, maybe you can think of some way to improve on it? Just food for thought.


----------



## Thonex (May 8, 2006)

Big Bob @ Mon May 08 said:


> Andrew, why not wait a little on posting it as a module until we all get a chance to play with it and kick it around a little.



Will do :smile:


----------



## Big Bob (May 9, 2006)

Hi Nils,



> Bob, sorry I didn't adress your idea about making this callable in a general way. I'm all for that, but currently I don't have any script where I need to use this functionality (although I'm sure that something will turn up sooner or later). If anyone comes up with a scheme of how to invoke this functionality in a general way please post it.


I'm working on the next update for SIPS which will incorporate a lot of these kinds of ideas and utilize some of the new features added to V2.1 of the KSP. 

By the time I get it done, I'm sure that a lot of this kind of stuff will be modularized, so if no one has posted actual, re-useable modules by then, I'll post what I have. In the meantime, I'm sure others will easily be able to adapt the ideas you posted already without too much difficulty. However, it will be kind of nice when we get a lot of these functions standardized.

And those of you who haven't updated to Nils' V0.98 should do so. This editor is getting better all the time. If Nils keeps improving this thing, pretty soon the scripts will write themselves :wink: .

God Bless,

Bob


----------



## EvilDragon (May 26, 2010)

Thread necromancy! Here's a REAL keyboard utilizing new functions of KSP in K4! Can't be better than this!

Button labels refresh their look when pressing Shift, Ctrl, Tab!

http://img251.imageshack.us/i/ascii.gif/


----------



## Big Bob (May 26, 2010)

Hey ED

That's pretty 'spiffy', one of these days I'm going to update my K4 and actually start using it for some of this 'mouth-watering' stuff :lol: 

God Bless,

Bob


----------



## polypx (May 26, 2010)

You guys are just amazing. I'm blown away.

This has been on the KSP request list for ages I think, a text-entry system. And I wouldn't be surprised if it shows up quite soon in the future. (Obviously it's a lot quicker to type on the computer's keyboard than with a mouse.)

But damn. This playground is full of geniuses.

cheers
Dan


----------



## Thonex (May 27, 2010)

Big Bob @ Wed May 26 said:


> Hey ED
> 
> That's pretty 'spiffy', one of these days I'm going to update my K4 and actually start using it for some of this 'mouth-watering' stuff :lol:
> 
> ...



Bob!!!!! o-[][]-o o-[][]-o 

How are you my friend???!!!!

What have you been up to? Great to see you luring around these parts...

So... how've you been?

Cheers,

Andrew K


----------



## polypx (May 27, 2010)

> Thread necromancy! Here's a REAL keyboard utilizing new functions of KSP in K4! Can't be better than this!
> 
> Button labels refresh their look when pressing Shift, Ctrl, Tab!
> 
> http://www.imagesforme.com/upload/ca17a73d.png



Hey ED, is the script for this one available somewhere?

cheers
Dan


----------



## EvilDragon (May 27, 2010)

It is now 

Here's the NKP and source. Will work in K4.0.5.


----------



## polypx (May 27, 2010)

Thanks ED. Very nice layout.


----------



## Big Bob (May 28, 2010)

Hi Andrew,



> Bob!!!!!
> 
> How are you my friend???!!!!
> 
> ...



I've been fine my friend, just very, very busy. But then I'm sure you know what that's like :lol: 

Don't see too much of you around here lately either. Hopefully, one of these days we'll all get caught up and then we can have a happy reunion o-[][]-o .

God Bless,

Bob

PS Thanks for the script ED, I've filed it for future use.


----------



## EvilDragon (May 29, 2010)

Great, Bob!

If you can find a workaround for getting a backslash WITHOUT a space afterwards, that would be most awesome! I couldn't do it... :(


----------



## gmet (May 29, 2010)

Thanks for your offering ED. Nice to see some new blood round here!

Regards,

Justin


----------

