Post Reply 
my 1st program "Virtual Keyboard" [POC]
10-02-2015, 11:31 AM (This post was last modified: 10-06-2015 03:38 PM by primer.)
Post: #1
my 1st program "Virtual Keyboard" [POC]
Hello,
Here is my first program, a virtual keyboard for the prime, because changing orange key can't be performed by a firmware update Tongue
Well, don't be too enthusiastic, it's a first version, I had 2 free hours, it's only a "Proof of concept", it's ugly and not yet feature complete.

But at least, here are working features :
* moving cursor with left/right keys
* accept entry with ENTER key (or tap on right side)
* cancel entry by ESC key
* adding char at the end of the or in the middle (depending on cursor location)
* removing char at the end or middle... with "<=" (del) key.
* space key to add a space
* blinking cursor Smile

[Image: x5cp69.png]

Run the program with vkb or in USER mode with alpha dot key (.)

As it's a very first version, you may encounter bugs, you are wellcome to report it.

Note
I had trouble to work with MOUSE(), there is probably a way to enhance what I did, if someone want to take a look at my getmouse() function to leave me advices. I'm not sure if I should better check for MOUSE(4)==1 for type or not...

There is a feature that is not developed yet is to switch upper/lowercase...
more feature to come, depending on your interests...

Code:

// vkb  : virtual keyboard, by prime
// version 0.8 - 1st Oct 2015
// assigned on alpha-dot key

#pragma mode( separator(.,;) integer(b32) )


// forward decls (for main only)
drawkb();
drawtxt(txt);
chkkey();
addchar(c);

// main vars
local t:=150; // top pos kb
local f; // end req
local txt:=""; // text
local curs:=0; // cursor pos

// main prog
EXPORT vkb()
BEGIN
 local c:=""; // char
 f:=0;
 txt:="";
 curs=0;
 drawkb();
 REPEAT
  drawtxt();
  c:=chkkey();
  if c≠"" then addchar(c); end;
 UNTIL f;

 IF f==1 THEN
  RETURN(txt);
 ELSE
  RETURN (""); // cancelled
 END;
END;


//--- keys
//decl
movecurs(d);
getmouse();
dropchar();

chkkey()
BEGIN
 local k,m;
 // keyboard chk
 k:=GETKEY();
 CASE
  IF k==7 THEN // <-
   movecurs(-1);
  END;
  IF k==8 THEN // ->
   movecurs(1);
  END;
  IF k==19 THEN // del
  dropchar();
  END;
  IF k==30 THEN // ENTER
   f:=1; // ends
  END;
  IF k==4 THEN // esc
   f:=2; // ends
  END;
  IF k==49 THEN // spc
   return (" ");
  END;
 END; // case
 if f THEN RETURN ""; END;
 //mouse chk
 m:=getmouse();
 if m>0 then return CHAR(m+64); end;
 RETURN "";
END;

LOCAL r:=0; // release key
// get "key" from mouse
// return 1-26 for A-Z
getmouse()
BEGIN
 local x:=MOUSE(0);
 if x==-1 then r:=1; return 0; end; // no mouse activity
 if x>270 then f:=1; r:=1; return 0; end; // tap ok
 x:=IP(x/30);
 IF r==0 THEN RETURN 0; END; // not released
 r:=0; // pressed
 local y:=MOUSE(1);
 if y<150 then return 0; end; // out of scope
 y:=IP((y-150)/30);
 RETURN 1+x+(y*9);
END;

// move cursor position
movecurs(d)
BEGIN
 local n:=curs+d;
 if n<0  then  n:=0;  end;
 if n> DIM(txt)  then  n:=DIM(txt);  end;
 curs:=n;
END;


//--- txt
// decl
txtwcurs(c); // add cusror to the txt
local alt:=0; // alternance
drawtxt()
BEGIN
  rect_p(8,100,312,120,#AAAAAAh,#FFFFFFh);// clear txt
 if alt==0 then
  textout_p(txtwcurs("  "),10,100);
  alt:=1;
else
  textout_p(txtwcurs(CHAR(#25C1h)),10,100);
  alt:=0;
end;
WAIT(0.13);
END;

txtwcurs(c) // add cusror/char to the txt
 BEGIN
 local a:="";
 local b:=MID(txt,1+curs);
 if curs>0 then a:=LEFT(txt,curs); end;
 if curs==DIM(txt) then b:=""; end;
 RETURN a+c+b;
END;

// add a char to the string
addchar(c)
BEGIN
 txt:=txtwcurs(c);
// curs:=curs+1;
 movecurs(1);
END;

dropchar()
BEGIN
 local a:="";
 local b:=MID(txt,1+curs);
 if curs>1 then a:=LEFT(txt,curs-1); end;
 if curs==DIM(txt) then b:=""; end;
 txt:=a+b;
 movecurs(-1);
END;

//--- kb
drawatpos(x,y,c); // decl

drawkb()
 begin
 local a;
 rect_p(0,t,320,240);
 for a from 0 TO 90 step 30 do
  line_p(0,t+a,320,t+a);
 end;
 for a from 0 TO 270 step 30 do
  line_p(a,t,a,240);
 end;
 
 for a from 0 TO 25 do
  local x:=a MOD 9;
  local y:= IP(a/9);
  drawatpos(x,y,CHAR(65+a)); //65 up 97 lo 
 end;
 
 drawatpos(7.9,2,"aA"); // switch up/lo
 drawatpos(9,0,CHAR(#2713h)); //OK

 //FREEZE;
end;

drawatpos(x,y,c)
 begin
  textout_p(c,G0,10+x*30,t+8+y*30);
end;

//--- key assignation : dot key on alpha
KEY KA_Dot
BEGIN
 RETURN vkb();
END;

KEY SKA_Dot
BEGIN
 RETURN vkb();
END;


.hpprgm  vkb.hpprgm (Size: 6.12 KB / Downloads: 23)
edit : new vesion : key must be released, #pragma added
Let me know your feeling.
Best Regards,


Attached File(s) Thumbnail(s)
   

primer
Find all posts by this user
Quote this message in a reply
10-02-2015, 11:37 AM
Post: #2
RE: my 1st program "Virtual Keyboard" [POC]
Awesome ! I love this blinking cursor. We could use it in custom text and formula editor.
Find all posts by this user
Quote this message in a reply
10-02-2015, 11:48 AM
Post: #3
RE: my 1st program "Virtual Keyboard" [POC]
(10-02-2015 11:37 AM)xset Wrote:  Awesome ! I love this blinking cursor. We could use it in custom text and formula editor.
Thank you,

In fact, this blinking cursor is just a quick workaround, because I wanted first to have a blue cursor, but because of that it was not possible Wink

I don't like so much the way I implemented it because I re-draw every time the text with the (blinking) cursor, it's not what I planed to do if I had a way to get width and height of a textout. Also the box around the text could have correct height with such a function.

Regards,

primer
Find all posts by this user
Quote this message in a reply
10-02-2015, 02:04 PM
Post: #4
RE: my 1st program "Virtual Keyboard" [POC]
I get an error syntax here:
https://cloudup.com/cSoRYBbru8x

But great idea! maybe it will be possible to write a proper UI all in user code haha! with the editor xset wants to make, etc.

My website: erwin.ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
10-02-2015, 04:21 PM
Post: #5
RE: my 1st program "Virtual Keyboard" [POC]
a quick update,
- added #pragma that could help to fix issue
- changed the way it acquire key by mouse : you must release your finger : this is to avoid too much key to be scanned when holding too long the screen.

new version on first post.

primer
Find all posts by this user
Quote this message in a reply
10-03-2015, 01:46 PM
Post: #6
RE: my 1st program "Virtual Keyboard" [POC]
(10-02-2015 11:48 AM)primer Wrote:  In fact, this blinking cursor is just a quick workaround, because I wanted first to have a blue cursor, but because of that it was not possible Wink

I think I have a solution to your problem. Tonight I'll show functions that calculate the width and height of the text very quickly Smile

Piotr Kowalewski
Radioactive Wastes - game for HP Prime
Find all posts by this user
Quote this message in a reply
10-03-2015, 07:49 PM
Post: #7
RE: my 1st program "Virtual Keyboard" [POC]
Here is the solution:
http://www.hpmuseum.org/forum/thread-485...l#pid43391

Note that these functions overwrite the G9 GROB.

Piotr Kowalewski
Radioactive Wastes - game for HP Prime
Find all posts by this user
Quote this message in a reply
10-03-2015, 09:56 PM (This post was last modified: 10-03-2015 10:04 PM by ji3m.)
Post: #8
RE: my 1st program "Virtual Keyboard" [POC]
Great. But is it possinle to post a .txt file. These can be cross loaded to the prime for android.
hpprgm cannot (as ive tried) since they are pseudo binary (they show in some text editors,but are really ghosts).

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
10-04-2015, 09:15 PM (This post was last modified: 10-04-2015 09:21 PM by primer.)
Post: #9
RE: my 1st program "Virtual Keyboard" [POC]
Hi,
(10-03-2015 07:49 PM)komame Wrote:  Here is the solution:
http://www.hpmuseum.org/forum/thread-485...l#pid43391

Note that these functions overwrite the G9 GROB.
Thank you very much koname, I was not here these days, I'll check your solution.

(10-03-2015 09:56 PM)ji3m Wrote:  Great. But is it possinle to post a .txt file. These can be cross loaded to the prime for android....
Hi ji3m, did you try the inline code from 1st post? I've copied and paste my program in text mode in the post itself, let me know (pm) if you can't use it ?

Regards,

primer
Find all posts by this user
Quote this message in a reply
10-08-2015, 12:38 PM
Post: #10
my 1st program "Virtual Keyboard" [beta]
Hi,

Here is beta version for virtual keyboard.

Changelog:
  • Allow numbers (0~9) and dot key
  • Implemented the upper/lower switch
  • Change cursor by a graphic one
  • Much less hysterical blinking for cursorWink
  • Removed animation glitches on small and big fonts.

[Image: n6rty8.png]


.hpprgm  vkb.hpprgm (Size: 10.76 KB / Downloads: 21)

Best Regards,

primer
Find all posts by this user
Quote this message in a reply
10-09-2015, 04:14 PM
Post: #11
RE: my 1st program "Virtual Keyboard" [POC]
indisputably! it is a very nice program, and very nice UI. Excuse my ignorance! but where can I actually use this keyboard? because right now it only shows any text I type in it. Is this the way we are supposed to use it? I mean what's the point to display a text and then it goes away?

Spybot.
Find all posts by this user
Quote this message in a reply
10-09-2015, 07:53 PM
Post: #12
RE: my 1st program "Virtual Keyboard" [POC]
(10-09-2015 04:14 PM)Spybot Wrote:  indisputably! it is a very nice program, and very nice UI. Excuse my ignorance! but where can I actually use this keyboard? because right now it only shows any text I type in it. Is this the way we are supposed to use it? I mean what's the point to display a text and then it goes away?

It is only a proof of a concept. It will never be an overlay or something used system wide without proper system extensions.

My website: erwin.ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
10-09-2015, 08:35 PM
Post: #13
RE: my 1st program "Virtual Keyboard" [POC]
(10-09-2015 07:53 PM)eried Wrote:  It is only a proof of a concept. It will never be an overlay or something used system wide without proper system extensions.
Indeed, I only allow to type new text, you cant edit (modify) a program for example.

(10-09-2015 04:14 PM)Spybot Wrote:  Is this the way we are supposed to use it? I mean what's the point to display a text and then it goes away?
no, it does not go away, you press ENTER and text you typed is now on your entry.
for example, you can go to program, "new" and then (in user mode) alpha-dot gives the vkb, you type a function name, enter, and what you typed is in your program.

What eried mentioned about system extension is the fact, that once it's in your program you cannot modify it with vkb anymore. There will not probably have any way to integrate in the future, but ok... as it I find it helpfull enouh to use it every times I need to type a word. hence I share it in just case I'm not alone to find it usefull.

primer
Find all posts by this user
Quote this message in a reply
10-10-2015, 04:39 AM
Post: #14
RE: my 1st program "Virtual Keyboard" [POC]
I see, That was probably just a dumb question, no mean to bother anyone. thank you for the explanations.

Spybot.
Find all posts by this user
Quote this message in a reply
10-12-2015, 01:19 PM
Post: #15
RE: my 1st program "Virtual Keyboard" [POC]
(10-04-2015 09:15 PM)primer Wrote:  Hi,
(10-03-2015 07:49 PM)komame Wrote:  Here is the solution:
http://www.hpmuseum.org/forum/thread-485...l#pid43391

Note that these functions overwrite the G9 GROB.
Thank you very much koname, I was not here these days, I'll check your solution.

(10-03-2015 09:56 PM)ji3m Wrote:  Great. But is it possinle to post a .txt file. These can be cross loaded to the prime for android....
Hi ji3m, did you try the inline code from 1st post? I've copied and paste my program in text mode in the post itself, let me know (pm) if you can't use it ?

Regards,

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
10-12-2015, 01:25 PM
Post: #16
RE: my 1st program "Virtual Keyboard" [POC]
I did copy/paste of the inline sourc which I frequently do.
But it wont compile. It gives me an error on lines like

If c==".." then ....

The error is before the then word.
This is very strange so I thought maybe there were some bogus characters in the file.

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)