jiggling the mouse

 Delphi, dzLib  Comments Off on jiggling the mouse
Aug 262013
 

Did you ever want to prevent the screen saver to start because your program is displaying something and you didn’t want to force the user to move the mouse every now and then?

Until Windows XP it was possible to prevent the screen saver from becoming active by just handling the WM_SYSCOMMAND message with wParam = SC_SCREENSAVE like this:

procedure Tf_MeasurementGraph.AppMessage(var _Msg: TMsg; var _Handled: Boolean);
begin
  if FIsRecording then
    // prevent screen saver from starting
    if ((WM_SYSCOMMAND = _Msg.Message) and (SC_SCREENSAVE = _Msg.wParam)) then
      _Handled := True;
end;

This apparently stopped working with Windows Vista. Other options introduced then only work if there was no password protection on the screen saver. So I asked the Google oracle and found this answer on Stack Overflow.

My solution then is this procedure:

procedure JiggleMouse;
var
  Inpt: TInput;
begin
  Inpt.Itype := INPUT_MOUSE;
  Inpt.mi.dx := 0;
  Inpt.mi.dy := 0;
  Inpt.mi.mouseData := 0;
  Inpt.mi.dwFlags := MOUSEEVENTF_MOVE;
  Inpt.mi.time := 0;
  Inpt.mi.dwExtraInfo := 0;
  SendInput(1, Inpt, SizeOf(Inpt));
end;

Call it in regular intervals and the screen saver will not start.

This is now (or soon will be) in the u_dzOsUtils unit which is part of my dzlib utility library.

 Posted by on 2013-08-26 at 18:34

How to waste hours with computer problems

 Linux  Comments Off on How to waste hours with computer problems
Aug 232013
 

I just wasted several hours with yet another computer problem.

Some Background: We are using a Ubuntu based server which runs Samba as a file server for Windows computers. It also is a local name server and mail server. Yesterday it was that time again that I had to reboot it because of some Linux kernel update. I waited until everybody had gone home, the box rebooted, everything seemed fine.

Until this morning: The first problem was that there was no e-mail telling me about the automatic backup last night. Then my web browser (which uses a proxy running on the server) did not work. Also there were suspiciously no spam emails.

So I investigated and found that the name service did not work, but only on the server itself. All clients could use the service and got the expected answers. But fetchmail and lots of daemons running on the server itself did not work.

Many minutes later I put our Internet provider’s into

/etc/resolv.conf

and name resolution started to work again for external addresses. E-mail was still broken, and I became desperate so I went to
serverfault.com hoping that somebody much more knowledgeable than me might know this problem.

I got quite a few hints on what to check but no luck.

The solution was absolutely unexpected (at least to me):
The loopback interface was not started!

Starting it with …

ifup -v lo

… fixed the problem.

 Posted by on 2013-08-23 at 15:48

A web server as a shell script – in a single line

 Linux  Comments Off on A web server as a shell script – in a single line
Aug 162013
 

I just found this via Heise online:

Web server in one line of bash

I tried it and it works!

while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; cat index.html; } | nc -l 8080; done

You can replace index.html with any file you happen to want to transfer (also works for binary files).

After executing this, just point your browser to

whateverhostname:8080

and it will start downloading the file or in the case of index.html, will display it.

This is some serious case of genius!

 Posted by on 2013-08-16 at 17:58

Concatenating pdf files the easy way

 Linux  Comments Off on Concatenating pdf files the easy way
Aug 122013
 

I just had the need to concatenate several pdf files to a single one. Since my desktop computer is running Windows, I first tried to download and use some freeware utility. After the first one did not work as advertised and the second one tried to sideload some adware I stopped going that path and remembered that I had ssh access to several Linux boxes. So I clicked on the second Google result for “concatenate pdf” and was sent to Doei Doei which gave me the following solution:

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf file1.pdf file2.pdf [...]

I had to install Ghostcript (apt-get install ghostscript) for this to work, but after that, I ended up with a working pdf within seconds.

Please, nobody try to tell me again that Windows is more user friendly than Linux.

 Posted by on 2013-08-12 at 14:37