IIRC, capslock can’t be handled by applications. When people customize
capslock to do something else, what they actually do is to ask their OS to
redirect the capslock keypress to other keys (say, F2), and then intercept
these other keys instead.

To catch keypresses like F2, create your own class that has text% as a
superclass, and override on-default-char.

On Sun, Dec 6, 2020 at 5:17 AM Christian Lykke <cmly...@hotmail.com> wrote:

>
> I would like to create an editor where I can use capslock
> or some other key to input special commands
> somewhat similar to M-x in emacs.
>
> with capslock (since I never use capslock anyway):
>
> every time I write someting in the editor, a function should
> run that will do something with the input.
> If capslock is turned off, the text should just be written
> in the editor normally.
> if capslock is on, then the text (letters, numbers ect)
> should instead be written
> in the field "commandField". if capslock is on and
> the input is a space or cariagereturn,
> then anoter function should run that takes the text
>  in the "commandField" field as its argument and executes a command.
> The command could be "increasesize" and
> then the function would run "select all" and then
> increase
> the font size by 1, and finally clear the "commandField".
> How could I do this?
>
> with some other key:
>
> It might be better to use another key than capslock,
> for example a function key.
> How could I create a boolean variable that
> changes everytime a specific key (for example f2)
>  gets pressed?
>
> Thank you !
>
> Here is the editor code I have so far:
>
> #lang racket
> (require racket/gui)
>
> ;first frame of the program
> (define firstFrame (new frame% [label "An editor that allow you to input
> commands"]
>                       [width 500]
>                       [height 500]))
>
> ;the commands you type should be vissible in this message control
> (define commandField (new message% [parent firstFrame]
>                           [label "no commands yet..."]))
>
> ;the text area
> (define mainCanvas (new editor-canvas% [parent firstFrame]))
> (define mainTextArea (new text%))
> (send mainCanvas set-editor mainTextArea)
>
> ;A menu bar for ordinary texteditor functionality
> (define manubar (new menu-bar% [parent firstFrame]))
> (define editDropdown (new menu% [label "Edit"] [parent manubar]))
> (define fontDropdown (new menu% [label "Font"] [parent manubar]))
>
> (append-editor-operation-menu-items editDropdown #f)
> (append-editor-font-menu-items fontDropdown)
> (send mainTextArea set-max-undo-history 100)
>
> (send firstFrame show #t)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/f07ba9b2-df26-4402-bb97-722d2c4f8d4dn%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/f07ba9b2-df26-4402-bb97-722d2c4f8d4dn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CADcuegudKjEi_a_bnC3SvUnTkVwokiwLzL%2BqK8OVBK9GG-ofDQ%40mail.gmail.com.

Reply via email to