If you change the event to keydown you will get extra event data that will tell you if any modifier keys are pressed.
Then inside the event callback you can check event.altKey to check if the alt key is currently pressed.
$(document).keydown(function(event) { if (event.altKey) { switch (String.fromCharCode(event.which)) { case 'A': console.log('Hi A') break case 'B': console.log('Hi B') break } } })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Here is a better example that will keep the state of all pressed keys, allowing you to test if more than one key is pressed at the same time. In the callback you have a function checkKeysPressed which takes the keys you wish to add the event for, if those keys are pressed the function will return true.
It's using ES6 syntax, functions and objects, but it could be converted to ES5 easily or just run through babel.
const multipleKeysEventListener = (element, callback) => { const keysPressed = new Set const describeKey = e => { switch(e.which) { case 18: return 'ALT' case 16: return 'SHIFT' default: return String.fromCharCode(e.which) } } const checkPressedKeys = (...keys) => keys.every(x => keysPressed.has( typeof(x) === 'number' ? String.fromCharCode(x) : x ) ) const down = e => { keysPressed.add(describeKey(e)) return callback(checkPressedKeys, e) } const up = e => { keysPressed.delete(describeKey(e)) } $(element).keydown(down) $(element).keyup(up) } multipleKeysEventListener(document, (checkKeysPressed, e) => { switch (true) { // you can pass keys case checkKeysPressed('A', 'B'): console.log('A and B pressed') break // you can pass modifiers case checkKeysPressed('ALT', 'A'): console.log('ALT and A pressed') break // and you can pass keyCodes case checkKeysPressed('ALT', 67): console.log('ALT and C pressed') break default: console.log(String.fromCharCode(e.which)) } })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Altis just my example. However it is possible to detect it?. If I pressAandBat the same time I want to alert somethingevent, likeevent.altKey(which tells you if Alt was down when the key was pressed). Modifier keys modify the key that was pressed when they were down.