Recent

Author Topic: ScreenShot Tool (BMP To ClipBoard + Cursor) Global Hotkey does nothing...  (Read 5350 times)

RAW

  • Hero Member
  • *****
  • Posts: 868
Hi,
I know how to handle one global hotkey...

Code: Pascal  [Select][+][-]
  1. UNIT Unit1;
  2.  {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Windows, Classes, SysUtils, Forms, Controls, Dialogs;
  7.  
  8.  TYPE
  9.   TWMHotKey = Packed Record
  10.    MSG   : Cardinal;
  11.    HotKey: PtrInt;
  12.    Unused: PtrInt;
  13.    Result: PtrInt;
  14.   End;
  15.  
  16.  TYPE
  17.   TForm1 = Class(TForm)
  18.  
  19.    Procedure FormCreate (Sender: TObject);
  20.    Procedure FormClose  (Sender: TObject; Var CloseAction: TCloseAction);
  21.  
  22.     PROTECTED
  23.      Procedure WMHotKey(Var MSG: TWMHotKey); Message WM_HOTKEY;
  24.   End;
  25.  
  26.  VAR
  27.   Form1: TForm1;
  28.  
  29. Implementation
  30.  {$R *.LFM}
  31.  
  32.  
  33. Procedure TForm1.FormCreate(Sender: TObject);
  34.  Begin
  35.   If Not RegisterHotKey(Handle, 111000, MOD_WIN, VK_S)
  36.   Then ShowMessage('HotKey failed...');
  37.  
  38.   // more Keys: MOD_CONTROL+MOD_ALT, VK_S
  39.  End;
  40.  
  41.  
  42. Procedure TForm1.WMHotKey(Var MSG: TWMHotKey);
  43.  Begin
  44.   // Show;
  45.  
  46.   ShowMessage('HotKey');
  47.  End;
  48.  
  49.  
  50. Procedure TForm1.FormClose(Sender: TObject; Var CloseAction: TCloseAction);
  51.  Begin
  52.   UnregisterHotKey(Handle, 111000);
  53.  End;
  54.  
  55. END.

..but I don't know how to handle several hotkeys...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

taazz

  • Hero Member
  • *****
  • Posts: 5368
well I do not see any problems. I made some minor changes mostly showing/hiding the main form and playing around with the application.showmainform and application.ExceptionDialog properties, I'm steel trying to enable debug information to see the blue dots in the IDE, but both the shortcuts work in my win7. What exactly is the problem you are having?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

RAW

  • Hero Member
  • *****
  • Posts: 868
Thank you very much... interesting the two global shortcuts don't do anything on my system...
Do I need dotNet 4.0 or something...
Do you have dotNet 4.0 installed ???

FormShow of course is not needed...  :D  I coudn't see the wood for the trees... I've used wndMAIN.Show in the LPR and didn't recognized that... funny...
Code: Pascal  [Select][+][-]
  1. BEGIN
  2.  RequireDerivedFormResource:= True;
  3.  
  4.  Application.Title:= 'ScrShotCursor';
  5.  Application.Initialize;
  6.   wndMAIN:= TwndMAIN.Create(Application);
  7.  Application.Run;
  8. END.

I'm trying right now to get it done without GlobalAddAtom...
EDIT: I try a callback function... maybe that's possible...
« Last Edit: August 06, 2017, 09:40:50 am by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

taazz

  • Hero Member
  • *****
  • Posts: 5368
Thank you very much... interesting the two global shortcuts don't do anything on my system...
Do I need dotNet 4.0 or something...
Do you have dotNet 4.0 installed ???
well dotNet 4.0  comes with visual studio 2015 one of life's little punishments but I doubt that it is required I'll try it on a windows XP VM in a couple of minutes.

EDIT:
Tried it on windows XP sp3 no visual studio installation works like a charm should I upload the exe somewhere to test it your self?
« Last Edit: August 06, 2017, 10:09:46 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

RAW

  • Hero Member
  • *****
  • Posts: 868
Quote
Tried it on windows XP sp3 no visual studio installation works like a charm should I upload the exe somewhere to test it your self?
Yes... if you don't mind... do you have got my email address (must be in one of the last PM's) ?? Maybe you can send it to my email box...

I cannot use GlobalAddAtom I guess, but I don't get any error from it... weird...

I did it... it's working without GlobalAddAtom ... the callback function is working very fine...
Code: Pascal  [Select][+][-]
  1. Function WndCallback(MyHWND: HWND; uMSG: UINT; wParam: WParam;
  2.                      lParam: LParam): LRESULT; StdCall;
  3.  Begin
  4.   If (uMSG = WM_HOTKEY) And (WParam = HotKeyShot)
  5.   Then DoScrShot;
  6.  
  7.   If (uMSG = WM_HOTKEY) And (WParam = HotKeyQuit)
  8.   Then wndMAIN.Quit;
  9.  
  10.   Result:= CallWindowProc(wndMAIN.PrevWndProc, MyHWND, uMSG, WParam, LParam);
  11.  End;
  12.  
  13.  
  14. Procedure TwndMAIN.FormCreate(Sender: TObject);
  15.  Begin
  16.   SetBounds(1,1,1,1);
  17.   PrevWndProc:= Windows.WNDPROC(SetWindowLongPtr(Handle, GWL_WNDPROC,
  18.                                 PtrInt(@WndCallback)));
  19.  
  20.   If Not RegisterHotKey(Handle, HotKeyShot, MOD_WIN, VK_S)
  21.   Then ShowMessage('Global HotKey: WINKEY+S  failed (DoScrShot) !');
  22.  
  23.   If Not RegisterHotKey(Handle, HotKeyQuit, MOD_CONTROL+MOD_ALT, VK_Q)
  24.   Then ShowMessage('Global HotKey: CTRL+ALT+Q  failed (Quit) !');
  25.  End;
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

taazz

  • Hero Member
  • *****
  • Posts: 5368
Quote
Tried it on windows XP sp3 no visual studio installation works like a charm should I upload the exe somewhere to test it your self?
Yes... if you don't mind... do you have got my email address (must be in one of the last PM's) ?? Maybe you can send it to my email box...

I cannot use GlobalAddAtom I guess, but I don't get any error from it... weird...
That's almost impossible, GlobalAddAtom is used in all sorts of synch in windows any kind of bug would have surface years back.
Here is the exe.
https://mega.nz/#!4xMESTqL!dRywr5Avc-BadgeklHthx9-P7VPoq2bF0VBu_LSipQY

Oh try to run it twice you should get the error message about not able to register the hot keys
« Last Edit: August 06, 2017, 10:36:39 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

RAW

  • Hero Member
  • *****
  • Posts: 868
@taazz
Thanks, I will try it later... my browser cannot reach the site...
It's probably my Firefox-browser, I changed appox. 300 values inside about:config ... the browser isn't even loading... weird...
I try to use another browser...  :)

EDIT: There is no error message, maybe a cypher problem...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

taazz

  • Hero Member
  • *****
  • Posts: 5368
more than one way to skin a cat (I think that's the correct saying).
https://sourceforge.net/projects/codelibrarian/files/3rdParty/ScrShotCursor.rar/download
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

RAW

  • Hero Member
  • *****
  • Posts: 868
BTW: Do you know www.tinyupload.com ?
I've never used it before, but I want to use this for PDF-files in the future, looks nice 50MB, no login and everything is free...

Hey thanks, got your exe-file... guess what... it's working... WTF  :D   I need to check things... I don't get it right now...
Do you changed the MouseRight&LeftClick, it's not working anymore...  :)
really funny...

EDIT: OK, you prefer doubleclicks...  :D
« Last Edit: August 06, 2017, 11:20:49 am by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

taazz

  • Hero Member
  • *****
  • Posts: 5368
BTW: Do you know www.tinyupload.com ?
I've never used it before, but I want to use this for PDF-files in the future, looks nice 50MB, no login and everything is free...

Hey thanks, got your exe-file... guess what... it's working... WTF  :D   I need to check things... I don't get it right now...
Do you changed the MouseRight&LeftClick, it's not working anymore...  :)
really funny...

EDIT: OK, you prefer doubleclicks...  :D
yeah I added a popup menu. I hate mouse down actions make me very jumpy. well at least I thought I added one, it seems it does not work. I'll upload the source too in a bit.

EDIT:
  I replaced the exe with the source on sourcefrge https://sourceforge.net/projects/codelibrarian/files/3rdParty/ScrShotCursor.rar/download

I'll probably deleted in 48 hours or so.
« Last Edit: August 06, 2017, 11:49:05 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

RAW

  • Hero Member
  • *****
  • Posts: 868
Quote
I'll probably deleted in 48 hours or so.
Thanks.. got it... you can delete it...  :D

Meanwhile I installed the crosscompiler and compiled it for x86 and it works !!!
So it's a x64/x86-thing I guess... I don't know right now... think I figure it out... thanks again...

EDIT: Now I know 3 ways to handle global hotkeys... nice ...  :D

EDIT:
Quote
Oh try to run it twice you should get the error message about not able to register the hot keys
Yes, nice, I can see the ShowMessage Error message...
That's strange maybe I should take a look at the winAPI "wiki"-page... why is there something different with a x64-exe... hmmm...
« Last Edit: August 06, 2017, 12:13:20 pm by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

taazz

  • Hero Member
  • *****
  • Posts: 5368
main difference between 32 and 64 bit that comes to mind is the SEH handler that is enabed by default on 64bit.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018