Recent

Author Topic: How to launch a desktop shortcut for an application?  (Read 1150 times)

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
How to launch a desktop shortcut for an application?
« on: March 23, 2022, 07:14:01 am »
hey, I would like to know how you can programmatically click on a desktop shortcut for an application like say notepad.

I found a code that lets you create a desktop shortcut. I would like to know how you click on it or execute the shortcut.


Thanks.
« Last Edit: March 27, 2022, 05:10:33 pm by Awesome Programmer »

dbannon

  • Hero Member
  • *****
  • Posts: 2802
    • tomboy-ng, a rewrite of the classic Tomboy
Re: How to click on a desktop shortcut for an application?
« Reply #1 on: March 23, 2022, 08:17:56 am »
Maybe it would make more sense to run eg notepad directly ?

https://wiki.freepascal.org/Executing_External_Programs

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11458
  • FPC developer.
Re: How to click on a desktop shortcut for an application?
« Reply #2 on: March 23, 2022, 09:20:59 am »
Execute over shellexecute()

RayoGlauco

  • Full Member
  • ***
  • Posts: 179
  • Beers: 1567
Re: How to click on a desktop shortcut for an application?
« Reply #3 on: March 23, 2022, 11:21:38 am »
You can simulate a mouse clic as this example shows. But the previous answers are quite right.

Code: Pascal  [Select][+][-]
  1. uses JwaWinUser
  2.  
  3. procedure MouseButtonDown(rightbutton: boolean);
  4. var
  5.   Input: TInput;
  6. begin
  7.   FillChar(Input, SizeOf(Input), 0);
  8.   Input.mi.mouseData := 0;
  9.   Input.mi.dx := 0;
  10.   Input.mi.dy := 0;
  11.   Input.type_ := INPUT_MOUSE;
  12.   if rightbutton then
  13.     Input.mi.dwFlags := MOUSEEVENTF_RIGHTDOWN
  14.   else
  15.     Input.mi.dwFlags := MOUSEEVENTF_LEFTDOWN;
  16.   SendInput(1, @Input, SizeOf(Input));
  17.  
  18. procedure MouseButtonUp(rightbutton: boolean);
  19. var
  20.   Input: TInput;
  21. begin
  22.   FillChar(Input, SizeOf(Input), 0);
  23.   Input.mi.mouseData := 0;
  24.   Input.mi.dx := 0;
  25.   Input.mi.dy := 0;
  26.   Input.type_ := INPUT_MOUSE;
  27.   if rightbutton then
  28.     Input.mi.dwFlags := MOUSEEVENTF_RIGHTUP
  29.   else
  30.     Input.mi.dwFlags := MOUSEEVENTF_LEFTUP;
  31.   SendInput(1, @Input, SizeOf(Input));
  32. end;        
  33.  
  34. procedure SendMouseClick(rightbutton: boolean);
  35. begin
  36.   MouseButtonDown(rightbutton);
  37.   sleep(30);
  38.   MouseButtonUp(rightbutton);
  39. end;    
  40.  
  41. end;
To err is human, but to really mess things up, you need a computer.

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
Re: How to click on a desktop shortcut for an application?
« Reply #4 on: March 27, 2022, 05:04:17 pm »
Well, I might not have been more clear with my post... I want my program to be able to execute a desktop shortcut knowing what the name of the shortcut is. I am not trying to run Notepad... that was just an example... :)

I wrote a program that creates a shortcut for a program on the desktop and I want to execute or "run" that shortcut.

Thank you all for the reply.

RayoGlauco

  • Full Member
  • ***
  • Posts: 179
  • Beers: 1567
To err is human, but to really mess things up, you need a computer.

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
Re: How to launch a desktop shortcut for an application?
« Reply #6 on: March 30, 2022, 05:43:58 pm »
Take a look on this topic:
https://forum.lazarus.freepascal.org/index.php?topic=1709.0

Thank you for your reply, but that question deals with creating a .ink shortcut. I already have a program that does. I want to be able to LAUNCH that .ink link I created from my program. How do you do that?


 

TinyPortal © 2005-2018