1

Is it possible to highlight text with your cursor in any program, like you do with str+c and start a tool with the highlighted text as argument?

As far as I know, in Linux as well as in Windows, one can call a script/program with a custom shortcut. I assume str+c just does the same, calling a little program with the highlighted text as argument. How to replicate this?

For demonstration purposes, let's take this C - program printing the value it was called with:

#include <stdio.h>
int main(int argc, char**argv){
    if(argc == 2){
        printf("program called with: '%s'\n", argv[1]);
    }
}

Can one type the text "HelloWorld" in Word for example, highlight it, and press something like str+alt+p, calling

someprogram.exe HelloWorld

or as for Linux

someprogram HelloWorld

I am really curious if this is possible.

Edit: I'm interested to know, how to replicate the clipboard.exe functionality. I have written a program "write_custom.exe" storing anything given as argument (argv[1]) in a text-file, after deleting it's previous content. Other programs can read the content of this text-file and so are able to use this custom clipboard. It's purpose is mainly for self-teaching.

As I am at the beginning of my codeing career, I only know C, but I am open for solutions in other languages as well. My goal is to run this write_custom.exe, with highlighted text as argument, on my computer and my Linux-VM.

  • Ctrl+C does *not* "start a little program" inside any (other) software. If text – or anything else, really – is supposed to end up on a system-wide clipboard, it's up to the software to actually send it there. But, I am not one hundred percent on how you think this would work in practice. That said, maybe you are looking for something like [this earlier question](https://stackoverflow.com/questions/6832203/access-clipboard-in-windows-batch-file). – Jongware May 09 '20 at 23:13
  • Of course this sort of thing it is possible. The author of Notepad++ included it: highlight the word or phrase in the text and press Alt-F2 to make an internet search. You can make your own tool to pick up whatever is on the clipboard, and select what you want to do with it. But as far as *"any solution in any other language is fine"* goes, you'll have to write it yourself. We don't supply code on demand. – Weather Vane May 09 '20 at 23:14
  • @WeatherVane actually I'm not trying to use the clipboard.exe, but try to recreate it myself, for understanding purposes of how it works. As you might have noticed, I'm quite at the beginning of my codeing career. My first thought was, maybe there is a simple solution, like a config file "str + c + " = "run clipboard.exe ". If this is more complex, I need to know vaguely how it happens, to know what I need to learn. Because, without knowing what to look up for, how to do it? – Frank Pirata May 10 '20 at 06:34
  • @usr2564301 I thought, str+c is running clipboard.exe with the highlighted text as first argument and that would be a system feature working on any program. If I code any GUI, I made the experience, I do not need to implement a method running clipboard.exe if text is highlighted and str+c is pressed, it happens automatically. I wonder if there is the possibility, to configure the operating system to run a program with another keyboard-command, taking the highlighted text as argument. I'm not trying to read the clipboard, even though this would be an interesting thing to learn as well. – Frank Pirata May 10 '20 at 06:42

1 Answers1

0

You might want to check out ncurses (Linux) and Console API (Windows). The code will not be cross-platform, but you can pretty easily write some code to make them share some basic behavior :).

PhotonFalcon
  • 894
  • 8
  • 10