Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Thursday, March 15, 2012

Kbd++ released : Track global Toggle key events

Finally after a lot of development effort and study of OS internals, Kbd++ is being released.

Essentially it is ...........

An utility to track the toggle key(CAPS, NUM, SCROLL) status of keyboard. This is particularly useful for Wireless keyboard users as wireless keyboards have no LEDs. Status of the LEDs is indicated using three icons in the System Tray with Balloontips(optional). It is being developed on C++/Qt and will currently target Windows and Linux boxes. Platform specific code are implemented using Win32 and X11 APIs.

Currently it is only supporting MS Windows. Windows implementation is based on Named Pipes (for IPC ) and Windows Hooks (for capturing global events). Linux implementation is on way and hopefully will be completed shortly.

Make sure you run the correct binaries on the correct architecture (x86/amd64), else the explorer might hang.



It is freely available at :
Qt Apps Kbd++

The source is hosted on the mercurial based public repository at BitBucket:
Kbd++ Source

The Linux implementation is yet a gray area........ need more study on that. An easy way out is monitoring the key state at regular intervals. However that will increase the CPU utilization. Hence need to look for some system specific way to do it.

One major disappointment during the life of the project has been a strange runtime error while using QLocalSoket from the injected DLL, which in debug mode said :

warning: ASSERT failure in QWinEventNotifier::QWinEventNotifier(): "Cannot creat
e a win event notifier without a QEventDispatcherWin32", file kernel\qwineventno
tifier_p.cpp, line 74 



Qt Centre had a long discussion thread on this, which says its a probable Qt bug ...
Qt Centre discussion thread

I had too replace the entire named pipe client implementation in the injected DLL, using Win32 API s for the same.

Monday, March 2, 2009

Directory Tree Deletion Code (rmdir or rm -f equivalent)

This is a directory removal code (rm -r or rmdir equivalent). It deletes all the files or subdirectories under the directory pointed to and also deletes the directory itself:

Signature : bool delTree(QString)
Argument : Path of the directory to be deleted as QString
Return Value: true on success/false on error

bool delTree(QString dir)
{
//Check whether the dir directory exists
if(QDir(dir).exists()){

//Construct an iterator to get the entries in the directory
QDirIterator dirIterator(dir);

while (dirIterator.hasNext()) {

//Get the file information
QString item= dirIterator.next(), fileName= dirIterator.fileName();
QFileInfo fileInfo= dirIterator.fileInfo();

//If entry is a file delete it
if(fileName!="." && fileName!=".."){

if(fileInfo.isFile()){
QFile::remove(item);
}
//If entry is a directory, call the deltree function over it again to traverse it
else if(fileInfo.isDir()){
delTree(item);
}
}
}
}else
return false;

//Move up the directory hierarchy by one level
//Delete the current directory
QDir currentDir(dir);
currentDir.cdUp();
return currentDir.rmdir(dir);

}