Comfort Curve Keyboard 3000 bug on Windows 10

Comfort Keyboard 3000I’ve been using the Microsoft Comfort Curve Keyboard 3000 for a number of years, and it’s mostly served me very well. However, since upgrading to Windows 10, the keyboard has shown an annoying bug. If I leave it for a few seconds without pressing anything then the keyboard seems to shut down. If any keys are held down at that point then the OS doesn’t notice when they get released. The result is it thinks the keys are still held until I pressed and release them again. Sami Korhonen has made a YouTube video demonstrating the same problem.

Read more Comfort Curve Keyboard 3000 bug on Windows 10

Why Python 3 doesn’t write the Unicode BOM

I’ve been using Python scripts to automatically edit and output Windows Resource files (*.rc) for C++ projects in Visual Studio 2013. When handling Unicode, Windows and Visual Studio always want little endian UTF-16 encoding, and the resource file should always start with the Unicode BOM (Byte Order Mark). However, despite the promises in the documentation, I was finding that Python wasn’t outputting the BOM automatically.

I nearly resorted to outputting it manually, but as is often the case with Python, it turns out the correct approach is simpler than it seems. Read more Why Python 3 doesn’t write the Unicode BOM

Output file encoding in Python 3

Unicode is becoming very widespread now (for good reason), and one of the great benefits of Python 3.x is that it handles Unicode natively. There are different ways to represent Unicode though, so how do you set the file encoding in Python when you’re writing out to file?

It’s not immediately obvious from some of the official documentation, but thankfully it’s not complicated. I’ll give a quick overview in this post. Read more Output file encoding in Python 3

Generate UTF-8 dictionaries using gettext

I’ve been setting up localisation for an application using a combination of the Boost Locale library and the widely used gettext tools. I’m wanting to work entirely in UTF-8 because that should be suitable for pretty much any language we’re likely to need at this point, hopefully avoiding problems of mixing encodings. However, I found that the tools kept falling-back to outdated character sets instead.

Fortunately, there’s a fairly easy solution which I’ll outline quickly in this post. Read more Generate UTF-8 dictionaries using gettext

Decimal places in a floating point number

Floating point numbers are a mainstay of programming in areas such as games, graphics, and simulation. On the whole, they are easy and intuitive to use. However, they have certain quirks and issues to be aware of. For example, their representation is inherently flexible and often approximate. This means there’s no definitive answer to the question of how many decimal places they can hold.

By looking at the way floating point numbers are stored, it’s possible to understand why this happens, and what precision is likely to be available. Hypothetically, it’s possible under certain circumstances to get up to about 45 decimal places in a C++ float, and 324 in a double. However, as we’ll see in this post, it depends on context.
Read more Decimal places in a floating point number

Emit audible warning from a batch script

Windows Batch (*.bat) scripting is archaic and painful, but occasionally useful for quick bits of environment setup. It’s not always obvious to the user when something has gone wrong though as it’s easy to lose the information amidst other text which scrolls by. An audible warning can be a useful alternative to draw attention to a problem.
Read more Emit audible warning from a batch script

How to check that a function is constexpr

I’ve been implementing quite a few simple C++11 constexpr functions in my ail (Avid Insight Library) project. While writing unit tests alongside it, I quickly realised that it would be very helpful to have code which verifies that a constexpr function is actually being evaluated at compile-time. It turns out that it’s remarkably easy to do.
Read more How to check that a function is constexpr

C++ constexpr functions

I’ve been very excited to see that Visual Studio 2015 supports the constexpr keyword in C++. It was introduced in the C++11 standard, and is being taken further in upcoming revisions.

There are a number of uses for the keyword, but the one which excites me the most is using it for writing functions which can be executed during compilation, potentially saving a lot of runtime overhead. In this post, I’ll show a couple of quick examples.
Read more C++ constexpr functions

Using C++ templates for size-based type selection

The standardisation of size-specific integer types in C/C++ is extremely useful for portability. That is, when you use types like uint16_t and int32_t, you know exactly what size of data type you’re getting (assuming your compiler supports it, which is usually the case unless you’re working with very specialist/embedded systems). This isn’t the case with the more traditional types like short and int whose sizes can vary from one compiler to another. However, the size is obviously part of the type name, meaning you need to alter declarations directly if you want to use a type of a different size.

Using the std::conditional template from C++11 lets you change this. Instead, you can have a template parameter which specifies the size you want (e.g. in bytes). The corresponding type declaration can be automatically deduced from there.
Read more Using C++ templates for size-based type selection

Remote control bug on first level of LEGO Batman

I bought “LEGO Batman: The Videogame” for PC today (it was going cheap on Steam!). In the first level, I got stuck for a while because of an odd bug. You’re supposed to remote control a little green car, but for some reason it wouldn’t always move.

In summary, the fix which worked for me was to enable Vertical Sync in the game’s graphics settings. More details below.

LEGO Batman screenshot

Read more Remote control bug on first level of LEGO Batman