Author Topic: Tutor App  (Read 6483 times)

0 Members and 1 Guest are viewing this topic.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Tutor App
« on: January 29, 2013, 06:00:57 pm »
EDIT:22 April 2013
This topic is now renamed Tutor App as the project has evolved. An updated version can be found at this post later in the topic.


(original post)

On TI-BD, there was an idea for simulating keypresses, so I offered my assembly program to simulate a keypress. But then they wanted to simulate a list of keypresses, so I finally started working on that. Currently, whenever the OS looks for keypresses (not while programs are executing), the hook looks for the hacked string 17 (AA11h) and if it contains data, it will read the numbers one at a time, executing the keypresses.

The keypresses are not getKey values. If you have used assembly keycodes (where Enter=9, for example), that is the set you will want to use. To simulate pressing [2nd]+[nobbc], add 56, to simulate [ALPHA]+[nobbc], add 112. So for example, [Graph]=49, [PRGM]=31, [MATH]=47. To open the graph screen, then press [2nd][prgm] and then select 1:ClrDraw, use:
Code: [Select]
"49,87,9
To do that, then select the A:Pen from the draw menu, add an additional 87,159 (159=112+47). Finally, the arrows are 1=down,2=left,3=right,4=up. Combining all this:
Code: [Select]
"49,87,9,87,159,9,2,2,2,2,1,1,1,1,3,3,3,3,4,4,4,4
That will select ClrDraw, then Pen, then it will draw you a box :)
Spoiler For List of Key Codes:
01      Down
02      Left
03      Right
04      Up

09    Enter
10    +
11    -
12    *
13    /
14    ^
15    Clear

17    (-)
18    3
19    6
20    9
21    )
22    tan(
23    vars

25    .
26    2
27    5
28    8
29    (
30    cos(
31    prgm
32    Stat
33    0
34    1
35    4
36    7
37    ,
38    sin(
39    APPS
40    XTON

42    sto>
43    ln(
44    log(
45    X^2
46    X^-1
47    Math
48    Alpha
49    graph
50    trace
51    zoom
52    window
53    Y=
54    2nd
55    mode
56      delete

255    [2nd][On]
254    [prgm][enter] displays prgmA (Even if it doesn't exist)
253    [2nd][Stat]
252    Displays LA (list A)
251    Disp If
250    [Graph]
249    Catalog
248    nothing
247    Same as FE
246    RAM Clear
Spoiler For How To Make Hacked Strings:
There are several "easy" ways, but they involve getting the hacked string name in a string, then use Rcl Ans in a program to paste the name their. They typically have funky names, so don't be alarmed if your string is named something like GDB1-- it is because the OS doesn't have real names for them, so it uses what it has. Anyways:
  • Xtravar Beta provides an easy way to select hacked variables. In this case, find the Strings, and search for String 17 (11h) it will have a name 'sigma'x.
  • You can use Celtic 3 to do det(17,"AA11
  • You can use BatLib to do dim(5,"AA11
  • Xtra will take a list input to create a hacked var token. This has an included opcode.

Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
Re: Simulated Keypresses
« Reply #1 on: January 29, 2013, 06:12:17 pm »
wow, that's pretty cool =D
how long is the delay between keypresses? does it just execute every single time the hook is called?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Simulated Keypresses
« Reply #2 on: January 29, 2013, 06:18:17 pm »
Thanks, and yes, there is no delay between keypresses. It can even press non-repeating keys multiple times in a row :)

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Simulated Keypresses
« Reply #3 on: January 29, 2013, 06:38:38 pm »
Sounds awesome, as always :P

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Simulated Keypresses
« Reply #4 on: January 30, 2013, 06:43:56 am »
I need to adjust the program a bit because I realised that I made a silly mistake. (Warning: This is complicated ASMy stuff): Since the keyhook automatically deletes the first element from the string once it is read, I ran into a problem when I made a key sequence to create and edit a program or equation. I realised this last night which is why I tested it and it is because the edit buffer is still open. I think that what I will do is if the edit buffer is open, I will just fill the bytes with 00 and treat those as null bytes, then when the edit buffer is closed, I will delete all the appropriate stuff.

Now, stuff I have been thinking of adding:
  • *<<number>> to execute a key press a number of times. This shouldn't be difficult to add.
  • For(number)<<key sequence>>End to execute a keysequence a number of times. This might be difficult to do since I will need to somehow keep track of which key to execute next.
EDIT: To give an idea of the syntax for *, I am thinking something like 3*7 will simulate pressing right 7 times. I already have the code planned for this, so if I have time today, I will try to have it implemented :)

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Simulated Keypresses
« Reply #5 on: January 30, 2013, 01:55:36 pm »
Yay, I finished something on my lunch break! Now you can do *[num] to execute a key press [num] times in a row. As well, I fixed the issue with modifiying the string while the edit buffer was open, so you can now use this program to create programs and modify them!

EDIT: I have attached an updated version. The new version allows you to set a delay for reading each key press. Now you can actually see what is going on making this program possibly an excellent tool for on-calc tutorials.

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Simulated Keypresses
« Reply #6 on: January 30, 2013, 07:12:06 pm »
This sure is amazing

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Simulated Keypresses
« Reply #7 on: January 30, 2013, 07:16:46 pm »
Hehe, I already started an idea on TI-Basic Developer about maybe creating an on-calc BASIC tutorial that steps users through the process of creating programs and how to use each command (like CtlgHelp, but much more involved). I have even started an idea for adding annotations so that you can inform the user what is happening at each step. I estimate that it would take one page to cover all of the commands and we could use a second page for the programming tutorials.

EDIT: I started making an app with some simple scripty commands so that non-assembly programmers can contribute code. I plan to add in menus, but for now it automatically installs the Hello World example walkthrough thingy. The code looks like:
Code: [Select]
ex_helloworld:
     Delay(30)
;     Text(56,0,"New Program")
     Key(skprgm)
     Key(skright)
     Key(skright)
     Key(skenter)
     Key(skpower)      ;H
     Key(sksquared)     ;I
     Key(skminus)      ;W
     Key(sk7)          ;O
     Key(sktimes)      ;R
     Key(skrparen)     ;L
     Key(skinverse)    ;D
     Key(skEnter)
     Key(skClear)
     Key(skprgm)
     Key(skright)
     Repeat(skdown,7)
     Key(skEnter)

     Key(skEnter)
     Key(skprgm)
     Key(skright)
     Repeat(skdown,2)
     Key(skEnter)
     Key(sk2nd)
     Key(skAlpha)
     Key(skplus)
     Key(skH-112)
     Key(skE-112)
     Key(skL-112)
     Key(skL-112)
     Key(skO-112)
     Key(skSpace-112)
     Key(skW-112)
     Key(skO-112)
     Key(skR-112)
     Key(skL-112)
     Key(skD-112)
     Key(skAlpha)
     Key(skMath)
     Repeat(skRight,3)
     Repeat(skDown,3)
     Key(skEnter)
     Key(sk2nd)
     Key(skMode)

     Key(skPrgmToken)
     Key(sk2nd)
     Key(skAlpha)
     Key(skpower)      ;H
     Key(sksquared)    ;I
     Key(skminus)      ;W
     Key(sk7)          ;O
     Key(sktimes)      ;R
     Key(skRParen)     ;L
     Key(skinverse)    ;D
     Key(skEnter)
     ExitTutor()
It is 65 bytes, by the way.

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: Simulated Keypresses
« Reply #8 on: January 31, 2013, 12:22:59 pm »
That's really cool, Xeda.  On-calc tutorials would be neat :)

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Simulated Keypresses
« Reply #9 on: January 31, 2013, 10:00:20 pm »
Thanks! I finished up the main functions for the keyhook, now I need to add in a menu for the app to access the tutorials.
Code: (Current Supported Functions) [Select]
/=====================\
|    Key(val)         | 1 byte
\=====================/
  This is the main command. This tells the engine which key to
simulate. For example, to simulate [ENTER], use Key(skEnter).
/=====================\
|    Delay(val)       | 2 bytes
\=====================/
  This sets the delay between simulated key presses. I find 30
to work well.
/=====================\
|    Text(y,x,string) | 4 bytes + length of string
\=====================/
  This is how you communicate to the user. This is like the
BASIC command, except it draws over whatever is on the LCD, not
just the graph screen. For the worried, this does not affect the
contents of the graph screen. So for example:
     Text(56,0,"Hello World!")
/=====================\
|    WaitForKey(key)  | 2 bytes
\=====================/
  This waits for the user to press the appropriate key. When the
user presses the key, it will be registered. No other keys
respond while waiting.
/=====================\
|    Repeat(key,num)  | 3 bytes
\=====================/
  This will simulate a key press a number of times in a row.
This is useful for navigating menus to get to an item.
/=====================\
|    ExitTutor()      | 1 byte
\=====================/
  This ends the tutorial and normal OS stuff resumes.

  These commands should be enough for most tasks. However, if
there are more commands for the adventurous:
/=====================\
|    SetAns(num)      |
\=====================/
  This will set the "Ans" variable to the specified value. Note
that this whole program works with 1-byte values, 0 to 255.
/=====================\
|    TestAnsEqu(num)  |
\=====================/
  If 'Ans' is equal to 'num', then 'Ans' is set to 1, else it
is set to 0.
/=====================\
|    GetKey(num)      |
\=====================/
  Stores the user's keypress to Ans. This isn't as responsive
as it could be, yet, but it works.
/=============================\
|    JumpIfAnsEqu(num,label)  |  4 bytes
\=============================/
  This will jump to a label if Ans=num. Note that the label must
be on the same flash page.
/=====================\
|    PushAns()        |
\=====================/
  This pushes Ans onto a stack for later retrieval with
PopAns(). The stack is currently 240 bytes, but it may be
smaller in the future.
/=====================\
|    PopAns()         |
\=====================/
  This removes the last value on the stack and stores it to
'Ans'.
I think once I add in the menu the process will be much easier. I am glad I added in the ability to use Text() today because it makes it much more interactive :) The code that is used for the "tutorial" in the screenie is:
Code: [Select]
ex_helloworld:
     Key(skClear)
     Delay(30)
     Text(44,0,"First, we need to make")
     Text(50,0,"a new program. Press PRGM,")
     Text(56,0,"and the Tutor will do the rest.")
     WaitForKey(skPRGM)
     Key(skright)
     Key(skright)
     Key(skenter)
     Text(56,0,"Enter the program name")
     Key(skpower)      ;H
     Key(sksquared)     ;I
     Key(skminus)      ;W
     Key(sk7)          ;O
     Key(sktimes)      ;R
     Key(skrparen)     ;L
     Key(skinverse)    ;D
     Key(skEnter)
     Key(skClear)
     Key(skprgm)
     Key(skright)
     Repeat(skdown,7)
     Key(skEnter)
     Text(50,0,"Press ENTER to go to the")
     Text(56,0,"next line of code.")
     WaitForKey(skEnter)
     Key(skprgm)
     Key(skright)
     Repeat(skdown,2)
     Key(skEnter)
     Key(sk2nd)
     Key(skAlpha)
     Key(skplus)
     Key(skH-112)
     Key(skE-112)
     Key(skL-112)
     Key(skL-112)
     Key(skO-112)
     Key(skSpace-112)
     Key(skW-112)
     Key(skO-112)
     Key(skR-112)
     Key(skL-112)
     Key(skD-112)
     Key(skAlpha)
     Key(skMath)
     Repeat(skRight,3)
     Repeat(skDown,3)
     Key(skEnter)
     Key(sk2nd)
     Key(skMode)

     Key(skClear)
     Text(50,0,"Enter the program name,")
     Text(56,0,"then press ENTER to run it.")
     Key(skNULL)
     Key(skPrgmToken)
     Key(sk2nd)
     Key(skAlpha)
     Key(skpower)      ;H
     Key(sksquared)    ;I
     Key(skminus)      ;W
     Key(sk7)          ;O
     Key(sktimes)      ;R
     Key(skrparen)     ;L
     Key(skinverse)    ;D
     WaitForKey(skEnter)
     ExitTutor()

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: Simulated Keypresses
« Reply #10 on: February 01, 2013, 06:05:19 am »
Wow, that's just incredible! The text feature is a really nice touch.

What do you have in mind for the menus?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: On-Calc Tutorials
« Reply #11 on: February 01, 2013, 06:43:33 am »
Thanks! In code, I currently have this but I want to change it:
Code: [Select]
MainMenu:
     Menu("Command Index",cmdindex)
     Menu("Math Tutorials",mathtutorials)
     Menu("Programming Tutorials",programming)
     .db 0
programming:
     Item("Hello World",ex_helloworld,0)
cmdindex:
mathtutorials:
     .db 0
Anything labeled as a Menu() will open a new menu when it is selected and anything labeled as Item() well set it as the tutorial to use. I think I will make it a simple list that the user can scroll through and I think that I will change the format, too. This way the menu or item name is part of the data and there can be several organisation options. For example, a command that falls under several categories might be like this:
Code: [Select]
MainMenu:
     Menu(cmdindex)
     Menu(mathtutorials)
     Menu(probstattutorials)
     .db 0
cmdindex:
     .db "Command Index",0
     Item(cmd_nCr)
     .db 0

mathtutorials:
     .db "Math",0
     Item(cmd_nCr)
     .db 0

probstatstutorials:
     .db "Probability/Statistics",0
     Item(cmd_nCr)
     .db 0
cmd_nCr:
     .db "nCr",0
     .db tut_nCr
And now each menu is just an LUT of 3-byte elements. 1 byte is for the Menu/Item and 2 bytes for the pointer to the item data.

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Simulated Keypresses
« Reply #12 on: February 12, 2013, 04:17:52 pm »
Congratulations. If I'm understanding this correctly, it looks like you've made something similar to batch files to automate processes. Very cool! ^^

Offline tr1p1ea

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 647
  • Rating: +110/-0
    • View Profile
Re: Simulated Keypresses
« Reply #13 on: February 12, 2013, 05:25:18 pm »
Wow cool project! "Possessed calculators" :P.

It would be cool to use this in conjunction with compatible games for a walkthrough or 'replay' function.
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."


Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Simulated Keypresses
« Reply #14 on: February 12, 2013, 07:31:49 pm »
Yeah, I am not exactly sure what it is that I made. I know Runer said it was a macro and an IRL friend said it was like a macro that you would use in excel.

@tr1p1ea: I was thinking about that, but the OS doesn't let these hooks work during program execution unless you are at a Pause, Input, Menu( or something similar :[ It would be pretty awesome if it did, though.